trustroots icon indicating copy to clipboard operation
trustroots copied to clipboard

Convert translations from json to po and vice versa

Open mrkvon opened this issue 4 years ago • 8 comments

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

  1. git switch convert-translations-po
  2. 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
  3. 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
  4. both directions
    • create or edit various json and po files in public/locales
    • git add . && git commit -m "test"
    • see that their counterparts were generated/updated
  5. both directions with conflict
    • create or edit both json and po 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
  6. use script directly
    • run npm run convert-translations public/locales/**/*.json
    • see that everything got converted to po.

mrkvon avatar Mar 08 '20 02:03 mrkvon

Rebased.

simison avatar Mar 21 '20 16:03 simison

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?

simison avatar Mar 21 '20 16:03 simison

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)

simison avatar Mar 21 '20 17:03 simison

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.

mrkvon avatar Mar 30 '20 14:03 mrkvon

@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 avatar Mar 30 '20 14:03 mrkvon

@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.

simison avatar Mar 30 '20 15:03 simison

https://github.com/Trustroots/trustroots/pull/1289#issuecomment-606058175

The tests moved to /bin/i18n/tests/... in 7ff522c02dc66324b5c97dfca4eb29f03c4c9dae

mrkvon avatar Apr 02 '20 14:04 mrkvon

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.

mrkvon avatar Apr 02 '20 14:04 mrkvon

It seems this isn't useful since we use Weblate. Closing.

mrkvon avatar Jan 17 '24 15:01 mrkvon