Skip to content

Change i18n-extract-messages build step to merge components #846

@pwithnall

Description

@pwithnall

See #840 (comment)

The problem

Currently, the kolibri-tools i18n-extract-messages build utility is called multiple times by kolibri-explore-plugin, once for each component (template-ui, ek-components, the app). This was implemented in commit d4d678d because the utility only supports one --namespace/--searchPath argument pair.

This setup extracts the messages from each component into a CSV file named after the component, e.g. ek-components-messages.csv. This is then translated and committed as ek-components-messages.json.

At runtime, the webpack_asset tag (e.g. {% webpack_asset 'kolibri.core.default_frontend' %} in base.html) generates some inline JavaScript which calls kolibriCoreAppGlobal.registerLanguageAssets() on the translated messages, which are loaded from the JSON file and injected inline into the page in that call.

There is only a webpack asset for kolibri_explore_plugin.app, there is no webpack asset for ek-components or template-ui. This means that none of the runtime loading code actually loads the ek-components/template-ui messages in, and hence they are not translated at runtime.

There is prior art in Kolibri for how to handle translations from a sub-package, in the form of its kolibri-common package, which contains some common UI elements (and translations). It’s hooked in to the generated JSON file by kolibri-tools i18n-extract-messages: when passed an additional --namespace and --searchPath argument (for kolibri-common), it will extract messages from that namespace too, and bung them into the same output file.

This can be seen by doing ack -l searchPlaceholder in kolibri-explore-plugin vs ack -l resourcesUnavailable in Kolibri. The latter appears in kolibri/locale/*/LC_MESSAGES/kolibri.core.default_frontend-messages.json, whereas the former does not (and that means it’s not translated at runtime).

The fix

We need to revert d4d678d and instead change kolibri-tools i18n-extract-messages to support multiple --namespace/--searchPath pairs.

A short term workaround would be to manually move all the messages from {ek-components,template-ui}-messages.json into kolibri_explore_plugin.app-messages.json. But that would have to be repeated every time the strings are re-extracted or the translation is updated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions