|
| 1 | +Internationalisation of kolibri-explore-plugin |
| 2 | +=== |
| 3 | + |
| 4 | +Overview |
| 5 | +--- |
| 6 | + |
| 7 | +Internationalisation (i18n) of kolibri-explore-plugin works the same way as i18n |
| 8 | +of Kolibri, to the extent that the build rules are named the same. It’s done |
| 9 | +using tooling from kolibri-tools, and an overview of the system is given |
| 10 | +[in the Kolibri documentation](https://kolibri-dev.readthedocs.io/en/develop/i18n.html). |
| 11 | + |
| 12 | +An overview of i18n in Django is [here](https://docs.djangoproject.com/en/1.11/topics/i18n/), |
| 13 | +which covers the backend of kolibri-explore-plugin. |
| 14 | + |
| 15 | +At a high level, translatable strings are extracted from Python, JavaScript and |
| 16 | +Vue files, and are collated into several files: |
| 17 | + * `kolibri_explore_plugin/locale/en/LC_MESSAGES/django.po` |
| 18 | + * `kolibri_explore_plugin/locale/en/LC_MESSAGES/kolibri_explore_plugin-messages.csv` |
| 19 | + * `kolibri_explore_plugin/locale/en/LC_MESSAGES/welcome-screen-messages.csv` |
| 20 | + |
| 21 | +This extraction process is done by running `yarn i18n-extract`. |
| 22 | + |
| 23 | +They are in several files because they are extracted from the Django backend and |
| 24 | +the different node frontend modules separately. |
| 25 | + |
| 26 | +These files are checked into git, even though they are generated mechanically |
| 27 | +from the source code, so that translators or external translation tools can pick |
| 28 | +them up at any time, without having to run kolibri-tools on the code. |
| 29 | + |
| 30 | +Translations are done (currently manually), and the results committed to git as: |
| 31 | + * `kolibri_explore_plugin/locale/${locale}/LC_MESSAGES/django.po` |
| 32 | + * `kolibri_explore_plugin/locale/${locale}/LC_MESSAGES/kolibri_explore_plugin.app-messages.json` |
| 33 | + * `kolibri_explore_plugin/locale/${locale}/LC_MESSAGES/welcome-screen-messages.json` |
| 34 | + |
| 35 | +CSV versions of the JSON files are also available for review. |
| 36 | + |
| 37 | +The translated files for Django now need to be compiled to a machine readable |
| 38 | +form. This is done by `yarn i18n-download-translations`. (The naming is because, |
| 39 | +in Kolibri, this step downloads updated translations from a translation website |
| 40 | +before compiling them --- we do not currently do that in kolibri-explore-plugin.) |
| 41 | + |
| 42 | +It compiles the Django messages to the following file: |
| 43 | + * `kolibri_explore_plugin/locale/${locale}/LC_MESSAGES/django.mo` |
| 44 | + |
| 45 | +This is loaded by Django to provide backend translations. |
| 46 | + |
| 47 | +It also generates the following two files, which contain information about the |
| 48 | +locale (such as its name and currency and date formats). They are for use with |
| 49 | +the node [`intl`](https://www.npmjs.com/package/intl) and |
| 50 | +[`vue-intl`](https://www.npmjs.com/package/vue-intl) packages: |
| 51 | + * `kolibri_explore_plugin/assets/src/intl-locale-data.js` |
| 52 | + * `kolibri_explore_plugin/assets/src/vue-intl-locale-data.js` |
| 53 | + |
| 54 | +The frontend loads the installed source JSON files (such as |
| 55 | +`kolibri_explore_plugin/locale/${locale}/LC_MESSAGES/kolibri_explore_plugin.app-messages.json`) |
| 56 | +at runtime. It does this by looking for them using a well-known name in |
| 57 | +`LOCALE_PATHS`, then the `WebpackBundleHook.frontend_messages()` function |
| 58 | +injects the contents of the JSON files into the frontend JavaScript with a call |
| 59 | +to `kolibriCoreAppGlobal.registerLanguageAssets()` to register them with the |
| 60 | +translation functions. |
| 61 | + |
| 62 | +Configuration |
| 63 | +--- |
| 64 | + |
| 65 | +Internationalisation configuration is in two places: |
| 66 | + * `kolibri_explore_plugin/locale/language_info.json` |
| 67 | + * `setup.cfg` |
| 68 | + |
| 69 | +The JSON file contains the list of languages which we want kolibri-explore-plugin |
| 70 | +translated to. It’s in a format needed by kolibri-tools documented |
| 71 | +[here](https://kolibri-dev.readthedocs.io/en/develop/i18n.html#adding-a-newly-supported-language). |
| 72 | + |
| 73 | +`setup.cfg` is needed to point kolibri-tools at the right directories for |
| 74 | +extracting and compiling translatable strings. |
0 commit comments