Skip to content

Commit

Permalink
Ensure that we load the survey in the phone language
Browse files Browse the repository at this point in the history
Notably, when the phone language is Spanish, we want to load the spanish
version of the survey. This is apparently functionality that is in the most
recent version of enketo, but not in our older version.

We can apply the patch that introduced the change
enketo/enketo-core@c31dccc
but we can't do it directly since we only have the bundle included as a
manually imported library in our code.

So we apply the patch by copy-pasting. This works.

Difference between versions: e-mission/e-mission-docs#732 (comment)
Patch fix: e-mission/e-mission-docs#732 (comment)
  • Loading branch information
shankari committed Jun 3, 2022
1 parent 63515f3 commit cc81bed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions www/js/survey/enketo/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ angular.module('emission.survey.enketo.service', [
'emission.survey.enketo.answer'
])
.factory('EnketoSurvey', function(
$window, $http, UnifiedDataLoader,
$window, $http, $translate, UnifiedDataLoader,
InputMatcher, EnketoSurveyAnswer,
) {
/**
Expand Down Expand Up @@ -77,7 +77,9 @@ angular.module('emission.survey.enketo.service', [
external: opts.external || [],
session: opts.session || {}
};
_state.form = new $window.FormModule(formSelector, data, {});
const currLang = $translate.use();
_state.form = new $window.FormModule(formSelector, data,
{language: currLang});
return _state.form.init();
}

Expand Down
14 changes: 11 additions & 3 deletions www/manual_lib/enketo/enketo-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -48622,7 +48622,7 @@ var enketocore = (function () {
*/

var languageModule = {
init() {
init( overrideLang ) {
if ( !this.form ) {
throw new Error( 'Language module not correctly instantiated with form property.' );
}
Expand All @@ -48646,7 +48646,15 @@ var enketocore = (function () {
}
}
this.formLanguages = root.querySelector( '#form-languages' );
this._currentLang = this.formLanguages.dataset.defaultLang || languages[ 0 ] || '';


if ( overrideLang && languages.includes( overrideLang ) ) {
this._currentLang = overrideLang;
this.setUi( this._currentLang );
} else {
this._currentLang = this.formLanguages.dataset.defaultLang || languages[ 0 ] || '';
}

const langOption = this.formLanguages.querySelector( `[value="${this._currentLang}"]` );
const currentDirectionality = langOption && langOption.dataset.dir || 'ltr';

Expand Down Expand Up @@ -49419,7 +49427,7 @@ var enketocore = (function () {
this.calc.update();

// before itemset.update
this.langs.init();
this.langs.init( this.options.language );

// before repeats.init so that template contains role="page" when applicable
this.pages.init();
Expand Down

0 comments on commit cc81bed

Please sign in to comment.