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 the source code in the GitLab repository for each translatable string. 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/gitlab-org/gitlab/-/blame/master/ee/app/assets/javascripts/vue_merge_request_widget/components/approvals/utils.js#L27
+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/ee/app/assets/javascripts/security_orchestration/components/policy_drawer/scan_result/utils.js#L171
+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/ee/app/assets/javascripts/security_orchestration/components/policy_drawer/scan_result/policy_approvals.vue#L17
+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/app/assets/javascripts/vue_shared/components/awards_list.vue#L150
+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/app/assets/javascripts/vue_merge_request_widget/components/approvals/humanized_text.js#L7
msgid " and "
msgstr ""

+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/app/assets/javascripts/vue_shared/components/awards_list.vue#L147
msgid " and %{sliced}"
msgstr ""

+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/app/assets/javascripts/sidebar/components/confidential/sidebar_confidentiality_form.vue#L86
msgid " and leave a comment on"
msgstr ""

+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/ee/app/assets/javascripts/security_orchestration/components/policy_drawer/utils.js#L50
msgid " except branch:"
msgid_plural " except branches:"
msgstr[0] ""
msgstr[1] ""

+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/lib/gitlab/sentence.rb#L9
+#: https://gitlab.com/gitlab-org/gitlab/-/blame/master/app/assets/javascripts/alerts_settings/components/alert_mapping_builder.vue#L125
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:

Video16419762642

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