Skip to content

Frontend: Proper gettext extraction with gettext-extractor

Lukas 'ai-pi' Eipert requested to merge leipert-proper-gettext-parsing into master

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

  1. gettext_rails_i18n calls a new script scripts/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).
  2. 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 with vue-template-loader to js and passes it on to gettext-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?

What are the relevant issue numbers?

EE Port

https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6829

Edited by Lukas 'ai-pi' Eipert

Merge request reports