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:
parent
eb2afea2ab
commit
8472fa0807
2 changed files with 13 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
5
spec/fixtures/valid.po
vendored
5
spec/fixtures/valid.po
vendored
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue