trustroots
trustroots copied to clipboard
Convert translations from json to po and vice versa
Rationale
There are tools available for translating the gettext (.po) translations. Not so many for i18next format.
Therefore, let's keep both the json
and po
versions of the translations. This PR will help keep them in sync. Developers can generate json
files and translators can translate po
files.
Proposed Changes
- a script to convert translation files in
public/locales/{locale}/
from json to po and vice versa - pre-commit hook to do the conversion, when translation files are changed.
There may be more elegant solutions than this. I'm interested to hear about them, please!
If you can think of a better name or location for the tests, please share.
TODO
- [x] write the conversion scripts
- [x] make a pre-commit hook which will automatically convert json <-> po and keep them in sync
- [x] refactor, comment
- [x] format the output json file (has 4 spaces for tab instead of 2)
Testing Instructions
-
git switch convert-translations-po
- json to po
- create or edit files in
public/locales/{locale}/{translation}.json
-
git add . && git commit -m "test"
- see that their
.po
counterparts were generated/updated
- create or edit files in
- po to json
- create or edit files in
public/locales/{locale}/{translation}.po
-
git add . && git commit -m "test"
- see that their
.json
counterparts were generated/updated
- create or edit files in
- both directions
- create or edit various
json
andpo
files inpublic/locales
-
git add . && git commit -m "test"
- see that their counterparts were generated/updated
- create or edit various
- both directions with conflict
- create or edit both
json
andpo
with the same name and locale, e.g.public/locales/en/volunteering.{json|po}
-
git add . && git commit -m "test"
- see that the pre-hook will complain about conflict between json and po file
- create or edit both
- use script directly
- run
npm run convert-translations public/locales/**/*.json
- see that everything got converted to po.
- run
Rebased.
What do you think about placing modules/i18n/tests/server/convert-translation.bin.tests.js
under bin/i18n/test/*
so that it's easier to find and connect what it's testing?
fs-extra
needs to be added in dependencies; looks like it was a transient dependency earlier. We'll need eslint for these. :-) (opened https://github.com/Trustroots/trustroots/pull/1328)
fs-extra needs to be added in dependencies; looks like it was a transient dependency earlier.
What happened was the following: the fs-extra was removed in #1312. When this was rebased, we started missing fs-extra here. Now it's fixed again.
@simison wrote:
What do you think about placing modules/i18n/tests/server/convert-translation.bin.tests.js under bin/i18n/test/* so that it's easier to find and connect what it's testing?
I see the tests don't get executed when placed there. Do you think it's worth changing the gulpfile?
It seems that changing gulpfile#L116 and gulpfile#L149 would do the trick:
['modules/*/tests/server/**/*.js', 'bin/**/tests/**/*.js']
@simison I'd appreciate your opinion whether to do this, and some guidance when it comes to changing gulpfile. I haven't grokked the gulpfile, yet. :)
@mrkvon yeah, I think it makes sense. 👍 Let the Gulpfile serve us and not us serve the Gulpfile. 😅 Paths are regular globs so your change looks good.
https://github.com/Trustroots/trustroots/pull/1289#issuecomment-606058175
The tests moved to /bin/i18n/tests/...
in 7ff522c02dc66324b5c97dfca4eb29f03c4c9dae
Update:
Weblate seems to become our main translation tool. It supports i18next
, therefore the conversion between json
and po
seems unnecessary. Maybe nice to have, but a low priority. Definitely no need to reformat files before each relevant commit.
It seems this isn't useful since we use Weblate. Closing.