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

Project-level Python overrides live in the repository root translations/ directory (mounted at /opt/invenio/src/translations in local Compose). Package catalogs stay inside each installed package and are loaded via invenio_i18n.translations / translations_bundle entry points; they are merged in memory by invenio-i18n, not copied into the instance tree.

At build/setup time we compile the project catalog under src/translations, then symlink /opt/invenio/var/instance/translations → that directory (the same pattern as invenio-cli translations compile). The app reads the instance path; instance is only a pointer at the project catalog.

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

  • site/kcworks/dependencies/invenio-stats-dashboard/invenio_stats_dashboard/assets/semantic-ui/translations/invenio_stats_dashboard

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

From the root of the translation package you are working in (each directory has its own package.json). Prefer pnpm for consistency with the main app: enable Corepack once per Node install (corepack enable), then:

pnpm install
pnpm run extract_messages   # extract strings → JSON / .pot
pnpm run json_to_po         # .json → .po
pnpm run compile_catalog    # .po → .mo
pnpm run init_catalog language en   # new language + package.json list