Skip to content

Add code references to the `gitlab.pot` file

Martin Chrástek requested to merge mchrastek-gettext-references into master

What does this MR do and why?

The code changes introduce a new feature to include links to find the string in the source code in the GitLab repository. These links will help translators understand the context of the strings and make more accurate translations. Additionally, the code limits the number of reference links to 20 as it would be confusing to see several tens/hundreds of reference links for translators in Crowdin during translation.

This change is based on the following discussion: gitlab-com/localization/localization-team#13 (comment 2099659932)

Performance comparison

When I enabled the reference comments and timed the difference with time command, I saw that the real time spent was increased by ~23% (4 seconds) on a GitPod Standard instance:

before after
real 0m18.052s 0m22.237s
user 0m37.244s 0m37.858s
sys 0m4.217s 0m4.118s

gitlab.pot file structure changes

Here is a sample of the gitlab.pot file diff after this change:

+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+and+%5B%27%5C%22%60%5D%22+file%3Aee%2Fapp%2Fassets%2Fjavascripts%2Fvue_merge_request_widget%2Fcomponents%2Fapprovals%2Futils.js&regex=true
+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+and+%5B%27%5C%22%60%5D%22+file%3Aee%2Fapp%2Fassets%2Fjavascripts%2Fsecurity_orchestration%2Fcomponents%2Fpolicy_drawer%2Fscan_result%2Futils.js&regex=true
+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+and+%5B%27%5C%22%60%5D%22+file%3Aee%2Fapp%2Fassets%2Fjavascripts%2Fsecurity_orchestration%2Fcomponents%2Fpolicy_drawer%2Fscan_result%2Fpolicy_approvals.vue&regex=true
+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+and+%5B%27%5C%22%60%5D%22+file%3Aapp%2Fassets%2Fjavascripts%2Fvue_shared%2Fcomponents%2Fawards_list.vue&regex=true
+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+and+%5B%27%5C%22%60%5D%22+file%3Aapp%2Fassets%2Fjavascripts%2Fvue_merge_request_widget%2Fcomponents%2Fapprovals%2Fhumanized_text.js&regex=true
msgid " and "
msgstr ""

+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+and+%25%5C%5C%7Bsliced%5C%5C%7D%5B%27%5C%22%60%5D%22+file%3Aapp%2Fassets%2Fjavascripts%2Fvue_shared%2Fcomponents%2Fawards_list.vue&regex=true
msgid " and %{sliced}"
msgstr ""

+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+and+leave+a+comment+on%5B%27%5C%22%60%5D%22+file%3Aapp%2Fassets%2Fjavascripts%2Fsidebar%2Fcomponents%2Fconfidential%2Fsidebar_confidentiality_form.vue&regex=true
msgid " and leave a comment on"
msgstr ""

+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+except+branch%3A%5B%27%5C%22%60%5D%22+file%3Aee%2Fapp%2Fassets%2Fjavascripts%2Fsecurity_orchestration%2Fcomponents%2Fpolicy_drawer%2Futils.js&regex=true
msgid " except branch:"
msgid_plural " except branches:"
msgstr[0] ""
msgstr[1] ""

+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+or+%5B%27%5C%22%60%5D%22+file%3Alib%2Fgitlab%2Fsentence.rb&regex=true
+#: https://gitlab.com/search?project_id=278964&search=%22%5B%27%5C%22%60%5D+or+%5B%27%5C%22%60%5D%22+file%3Aapp%2Fassets%2Fjavascripts%2Falerts_settings%2Fcomponents%2Falert_mapping_builder.vue&regex=true
msgid " or "
msgstr ""

Screenshots or screen recordings

Here is a video showcasing how these reference links would be used by a translator within Crowdin to get more context about the translated string:

Video128667737322

There are a few dozen of strings that have quite a large number of these occurrences. For example the string "Actions" has 45 occurrences. This makes the Crowdin UI cluttered with links (see screenshot below), so I have limited the number of occurences that get into the gitlab.pot file to 20 occurrences.

image

How to set up and validate locally

  1. tooling/bin/gettext_extractor locale/gitlab.pot should create a diff with only the references added.
  2. bin/rake gettext:regenerate and bin/rake gettext:updated_check should also create the same diff as the tooling/bin/gettext_extractor locale/gitlab.pot command.
  3. Add an externalized string.
  4. When the commands above are run again after the addition, the diff should also include the new reference in code.

MR acceptance checklist

Edited by Martin Chrástek

Merge request reports

Loading