Frontend: Proper gettext extraction with gettext-extractor
What does this MR do?
We currently cannot extract strings that span multiple lines (#42839 (closed)) or if the n__
call spans multiple lines (#47092 (closed)). ruby is just doing regexes on each line instead of using the AST!
Extraction Solution Approach
-
gettext_rails_i18n
calls a new scriptscripts/frontend/extract_gettext_all.js
which extracts all externalized strings from*.{js,vue}
files. The communication between those scripts is done via JSON. The script is only called once on all files, as all calling once per file has a too big overhead (see below). - We are using the package gettext-extractor to extract the externalized strings from javascript files. I have created gettext-extractor-vue which compiles
vue
files withvue-template-loader
to js and passes it on togettext-extractor
Multiline string handling
Multi line strings are tricky. We are simply replacing newlines with spaces. So
<template>
{{
__s(`Context|
This is a nice multi
line
string
`)
}}
</template>
will turn into:
'Context| This is a nice multi line string'
Performance
I did some performance tests on the scripts:
Duration (h:mm:ss) | Comment |
---|---|
0:01:45 | Original timing (baseline) |
0:07:19 | Calling the script once per file |
0:02:07 | Calling the script once for all files |
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated -
API support added -
Tests added for this feature/bug - Conform by the code review guidelines
-
Has been reviewed by a UX Designer -
Has been reviewed by a Frontend maintainer -
Has been reviewed by a Backend maintainer -
Has been reviewed by a Database specialist
-
-
Conform by the merge request performance guides -
Conform by the style guides -
If you have multiple commits, please combine them into a few logically organized commits by squashing them -
Internationalization required/considered -
End-to-end tests pass ( package-and-qa
manual pipeline job)
What are the relevant issue numbers?
- Closes #47092 (closed)
- Closes #42839 (closed)
- Closes #48864 (closed)
EE Port
Edited by Lukas Eipert