Skip to content
Maikel edited this page Jun 19, 2018 · 24 revisions

Internationalisation (i18n) and Transifex

The OFN is available in several languages. You can help translating at Transifex.

Transifex and Github integration

Our code is on Github and that is where our source locale en is maintained. To enable people to translate it easily via Transifex, we need to feed it into Transifex and then get the translations back into Github again. Here is the story of the current process. Our main actors are Github, Transifex and our Continuous Integration (CI) server.

Quite regularly, a developer changes some code that involves changing text. Text is changed in the file config/locales/en.yml. Once that change has made it into our production code, the master branch on Github, it needs translating into all the other languages. Transifex is configured to check en.yml on Github every day and make any changes available for translation.

Translators may notice that their language is not 100% translated due to changes of the source file. Then they translate and once a language reaches 100% again, Transifex notifies our CI server.

Our CI server is running txgh to listen to Transifex. When a translation reaches 100%, it will download it from Transifex and push it to Github on the "transifex" branch. It will create the branch if it doesn't exist. It also opens a pull request so that we can easily merge the changes into master for the next release.

Please note that once a translation reached 100%, Transifex doesn't notify our CI server about any further changes. You can trigger another notification by reviewing the translation to 100%. Any updates after the review have to be downloaded and committed manually.

The Transifex client is a command line tool that helps with manually downloading translations. After installing, you can replace all locales with the latest Transifex version:

# cd openfoodnetwork
tx pull --force

Development

Clear cache after translation changes

When making changes to config/locales/en.yml or other locals, ensure you reload I18n js translations to see the changes in the application.

rake tmp:cache:clear

Scopes must be unique

Scopes/keys must be unique at all levels. If duplicated, they may work in the browser but can result in unrelated failing tests.

Bad

  shop:
    vegetables:
      carrot: 'carrot'
...
  shop:
    fruit:
      apple: 'apple'

Good

  shop:
    vegetables:
      carrot: 'carrot'
    fruit:
      apple: 'apple'...

JavaScript translations: Prefer Angular Filter over global t function

In JavaScript it's better to use our Angular filter for translations:

Bad join(" " + t('shop.products.filter_properties_or' ) + " ")

Good: join(" {{ 'shop.products.filter_properties_or' | t }} ")

In some cases we had problems with the global t function not working when called directly. I think it depends on the scope in which the code is running. Using the t filter is the safer option and we should try to be consistently using only that one in JavaScript.

Further reading

Clone this wiki locally