How are locales managed in ODK Tables

Hi there,

I keep looking for something like “getLocale” or “getDefaultLocale” for building my custom views but can not find it. Should I keep looking?
I have seen the one in odkcommon.js however it takes the locale of my cellphone, which doesnt correspond to the ones I use in my forms.

Also there is no way currently for a user to change the locale in Table?

Thanks,

Edouard

PS: I am posting this under “Support” because coding html/js is a feature of ODK tables, but maybe should it be under “Development”?

Hi Edouard,

You should be able to put application wide translations in the common_translations worksheet of your app-designer/app/config/assets/framework/forms/framework/framework.xlsx. The format of the common_translations worksheet is the same as what can be found in the framework_translations worksheet of the framework.xlsx file. The settings worksheet of the framework.xlsx file will also need to be updated with a setting for each locale. You can see examples of this in the framework.xlsx file in the app-designer directory. You will then need to convert the framework.xlsx using the XLSXConverter. You can run the XLSX Converter by typing “grunt” in the app-designer directory and selecting the “XLSX Converter” tab. After the conversion, choose “Save to File System”. The translations that you added to the framework.xlsx will be available in app-designer/app/config/assets/commonDefinitions.js.

When you want to access your translations in a JavaScript file, you will need to include app-designer/app/config/assets/commonDefinitions.js and app-designer/app/system/js/odkCommon.js. You will be able to retrieve the locale the user selected in the Tables Preferences->Device Settings->Default Locale by using odkCommon.getPreferredLocale() and then calling odkCommon.localizeText(locale, token_name) with the locale value and token name defined in the common_translations worksheet of framework.xlsx.

More information about translations can be found at Tool Suite Javascript framework and formDef.json (Survey) format · getodk/getodk Wiki · GitHub.

Oh gosh.
I totally missed out the “Preferences->Device Settings->Default Locale” and the 2-letter ISO 639-1.
I also need to spend more time on the js framework wiki before asking… Sorry and thanks a bunch Clarice!