Convert PO files to JS in node (14x faster)
What does this MR do and why?
We are currently using the gettext_i18n_rails_js
gem to convert our
translations from PO files to JavaScript. The process takes about 28
seconds on my machine. This is particularly painful during gdk update
and in CI where it is run every time we compile our assets.
With NodeJS we can compile the resulting file about twice as fast. If we
make use of parallel execution with the help of the battle-tested
jest-worker
, we can bring down the execution time to just about two
seconds, which is at least a 14x improvement and takes it from "what is
this doing" to barely noticing it.
Bringing this process into the Node world also will allow us:
- To potentially drop
gettext_i18n_rails_js
gem, as this is basically the only thing that was being used from the gem - Iterate on the resulting format and our usage of the
jed
library, as there is potential for size gains and performance gains. - Potentially fix some bugs. The conversion seems to escape a few characters which do not seem to need escapeing or where the escapes seem to be plain wrong.
For now none of these things have been changed and we focus on parity of
the results of the two processes. In order to verify the results, please
check out this commit and run bash scripts/frontend/po_to_json_spec.sh
Screenshots or screen recordings
N/A
How to set up and validate locally
Pinning test
- Check out
4cb85bf073f61350e2553fd24ed910b90ed2a97c
, the commit with the pinning tests. - Run
yarn install
- Run
bash ./scripts/frontend/po_to_json_spec.sh
- The tests generates the files the "old" and the "new" way and will compare them with a jest integration test
To check it end-to-end in the browser
- Go to the latest commit on the branch
- Remove compiled app.js files
rm -f app/assets/javascripts/locale/**/app.js
- Run
node scripts/frontend/po_to_json.js
- Start GDK and use a different language in the user profile settings (e.g. German or French)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.