ckan / ideas

[DEPRECATED] Use the main CKAN repo Discussions instead:
https://github.com/ckan/ckan/discussions
40 stars 2 forks source link

Support for JavaScript translations in extensions #176

Closed torfsen closed 7 years ago

torfsen commented 8 years ago

It seems that while CKAN extensions can provide their own i18n translation strings, these strings are only used in Python code and in the Jinja templates, but not in JavaScript.

As far as I understand it, the mechanisms for looking up translations differ quite a bit between Python (incl. templates) and JavaScript. While the former is done dynamically at runtime, the latter is done via JSON files that are statically generated using paster trans js before a release. The translations generated using paster trans js are then downloaded by the JavaScript client.

It seems that currently, paster trans js only takes CKAN's own translations into account, and not those added by extensions. I therefore see two possibilities for adding support for JavaScript translations in extensions:

  1. Make paster trans js gather translations not only from CKAN but also from the extensions.
  2. Generate an extension's JavaScript translations separately (similar to how it is now done for CKAN) and then combine all translations before serving them to the JavaScript client.

The first approach seems to be quite easy to implement but has some major drawbacks: For example, paster trans js would need to be re-run whenever you add or update an extension.

The second approach looks like more work but would be far easier to use once implemented.

torfsen commented 8 years ago

Regarding the second approach: The combination step could be done during server startup and cached until a translation file from CKAN or an extension changes.

torfsen commented 8 years ago

There is now a PR for this feature: ckan/ckan#3272. Feedback is welcome!

torfsen commented 7 years ago

ckan/ckan#3272 has been merged.