mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Always use %{count} in pluralized strings
This commit is contained in:
@@ -8,6 +8,7 @@ def extract_locale(path)
|
||||
end
|
||||
|
||||
PLURALIZATION_KEYS ||= ['zero', 'one', 'two', 'few', 'many', 'other']
|
||||
ENGLISH_KEYS ||= ['one', 'other']
|
||||
|
||||
def find_pluralizations(hash, parent_key = '', pluralizations = Hash.new)
|
||||
hash.each do |key, value|
|
||||
@@ -107,11 +108,33 @@ describe "i18n integrity checks" do
|
||||
expect(english_duplicates).to be_empty
|
||||
end
|
||||
|
||||
find_pluralizations(english_yaml).each do |key, hash|
|
||||
next if key["messages.restrict_dependent_destroy"]
|
||||
context "pluralizations" do
|
||||
wrong_keys = []
|
||||
invald_one_keys = []
|
||||
|
||||
it "has valid pluralizations for '#{key}'" do
|
||||
expect(hash.keys).to contain_exactly("one", "other")
|
||||
find_pluralizations(english_yaml).each do |key, hash|
|
||||
next if key["messages.restrict_dependent_destroy"]
|
||||
|
||||
wrong_keys << key if hash.keys.sort != ENGLISH_KEYS
|
||||
|
||||
if one_value = hash['one']
|
||||
invald_one_keys << key if one_value.include?('1') && !one_value.match?(/%{count}|{{count}}/)
|
||||
end
|
||||
end
|
||||
|
||||
it "has valid pluralizations keys" do
|
||||
keys = wrong_keys.join("\n")
|
||||
expect(wrong_keys).to be_empty, <<~MSG
|
||||
Pluralized strings must have only the sub-keys 'one' and 'other'.
|
||||
The following keys have missing or additional keys:\n\n#{keys}
|
||||
MSG
|
||||
end
|
||||
|
||||
it "should use %{count} instead of 1 in 'one' keys" do
|
||||
keys = invald_one_keys.join(".one\n")
|
||||
expect(invald_one_keys).to be_empty, <<~MSG
|
||||
The following keys contain the number 1 instead of the interpolation key %{count}:\n\n#{keys}
|
||||
MSG
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user