I18n

Translations

There are two separate translation systems in InvenioRDM: the python translations provided by the invenio-i18n package using the python babel library, and the javascript translations provided by the i18next library.

Python Translations

The python translations are stored in the translations directory in the root of the repository. These are then gathered with babel translations from other Invenio packages into the translations directory in the instance directory of the running instance (/opt/invenio/var/instance/translations).

Javascript Translations

The structure of the Javascript translation packages

The javascript translations are created and compiled by every InvenioRDM package that provides javascript UI components. These are found in the assets/semantic-ui/translations directory in each package. In the case of the kcworks package, these are found in the assets/semantic-ui/translations/kcworks directory.

In addition, KCWorks provides translations for the javascript components that live outside the installable kcworks python package: overridden components and custom field templates in assets/js. These translations are compiled and stored in the top-level assets/translations directory of the source folder.

So, for KCWorks, there are separate translation packages that are compiled independently in the following locations:

  • assets/translations

  • site/kcworks/assets/semantic-ui/translations/kcworks

  • site/kcworks/dependencies/invenio-modular-deposit-form/invenio_modular_deposit_form/assets/semantic-ui/translations/invenio_modular_deposit_form

  • site/kcworks/dependencies/invenio-modular-detail-page/invenio_modular_detail_page/assets/semantic-ui/translations/invenio_modular_detail_page

These are in addition to the translations provided by other InvenioRDM packages that come precompiled.

Each of these translation directories functions as a freestanding translation package, with its own package.json file, dependencies, and copies of the i18next object. The translation commands for each package are defined in that package’s package.json file and are executed from the root of that translation directory.

In each of these locations a separate instance of the i18next object is created in a freestanding i18next.js file. The components then import the i18next object from the translation directory attached to their own packages.

Compiling Translations

npm install  // this installs the dependencies
npm run extract_messages  // this extracts translatable strings from the javascript components, compiles them in a json file,and creates .pot files in the translations directory
npm run json_to_po  // this creates the .po files from the .json files
npm run compile_catalog  // this compiles the .po files into .mo files
npm run init_catalog language en  // this initializes a new language and adds it to the language list of the local package.json file