diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-08-14 11:46:09 +0200 |
---|---|---|
committer | MaĆgorzata Ksionek <mksionek@gitlab.com> | 2019-09-10 13:22:21 +0200 |
commit | 8472fa0807ad04f076df42b4ea4f8a145685dc80 (patch) | |
tree | 042740d7936e58338dfc074aee957b0025aa7153 | |
parent | eb2afea2abaa61978fae312a5a9b71293ab0e84a (diff) | |
download | gitlab-ce-8472fa0807ad04f076df42b4ea4f8a145685dc80.tar.gz |
Build correct variables for testing translations
This makes sure we build the correct variables for testing
translations.
When translating, we could be specifying the variables in different
forms for each id:
- In the singular we could be using a `%{hash}` interpolation
- In the plural we could be using a `%d` interpolation
This changes the tests to accommodate for that: We now use the
variables used in the relevant translation id as the source for the
variables we mix in in specs.
-rw-r--r-- | lib/gitlab/i18n/po_linter.rb | 11 | ||||
-rw-r--r-- | spec/fixtures/valid.po | 5 |
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/gitlab/i18n/po_linter.rb b/lib/gitlab/i18n/po_linter.rb index 3e9a035010f..aec3b1a3755 100644 --- a/lib/gitlab/i18n/po_linter.rb +++ b/lib/gitlab/i18n/po_linter.rb @@ -170,13 +170,18 @@ module Gitlab end def translate_plural(entry) - used_variables = entry.plural_id.scan(VARIABLE_REGEX) - variables = fill_in_variables(used_variables) + used_plural_variables = entry.plural_id.scan(VARIABLE_REGEX) + plural_variables = fill_in_variables(used_plural_variables) + + used_singular_variables = entry.msgid.scan(VARIABLE_REGEX) + singular_variables = fill_in_variables(used_singular_variables) numbers_covering_all_plurals.map do |number| translation = FastGettext::Translation.n_(entry.msgid, entry.plural_id, number) + index = index_for_pluralization(number) + variables = index == 0 ? singular_variables : plural_variables - translation % variables if used_variables.any? + translation % variables if variables.any? end end diff --git a/spec/fixtures/valid.po b/spec/fixtures/valid.po index 155b6cbb95d..28826f05595 100644 --- a/spec/fixtures/valid.po +++ b/spec/fixtures/valid.po @@ -1128,3 +1128,8 @@ msgid "parent" msgid_plural "parents" msgstr[0] "padre" msgstr[1] "padres" + +msgid "CycleAnalytics|%{stageName}" +msgid_plural "CycleAnalytics|%d stages selected" +msgstr[0] "%{stageName}" +msgstr[1] "%d stages selected" |