Commit 8472fa08 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Małgorzata Ksionek

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.
parent eb2afea2
...@@ -170,13 +170,18 @@ module Gitlab ...@@ -170,13 +170,18 @@ module Gitlab
end end
def translate_plural(entry) def translate_plural(entry)
used_variables = entry.plural_id.scan(VARIABLE_REGEX) used_plural_variables = entry.plural_id.scan(VARIABLE_REGEX)
variables = fill_in_variables(used_variables) 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| numbers_covering_all_plurals.map do |number|
translation = FastGettext::Translation.n_(entry.msgid, entry.plural_id, 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
end end
......
...@@ -1128,3 +1128,8 @@ msgid "parent" ...@@ -1128,3 +1128,8 @@ msgid "parent"
msgid_plural "parents" msgid_plural "parents"
msgstr[0] "padre" msgstr[0] "padre"
msgstr[1] "padres" msgstr[1] "padres"
msgid "CycleAnalytics|%{stageName}"
msgid_plural "CycleAnalytics|%d stages selected"
msgstr[0] "%{stageName}"
msgstr[1] "%d stages selected"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment