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.
This commit is contained in:
Bob Van Landuyt 2019-08-14 11:46:09 +02:00 committed by Małgorzata Ksionek
parent eb2afea2ab
commit 8472fa0807
2 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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"