Skip to content

Commit

Permalink
Add support for explicit 0 and 1 rules in #depluralize_key.
Browse files Browse the repository at this point in the history
  • Loading branch information
broekhuis00 committed Jan 13, 2025
1 parent d30e6bf commit ad846e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/tasks/plural_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ def plural_forms?(s)
end

def plural_suffix?(key)
PLURAL_KEY_SUFFIXES.include?(key)
PLURAL_KEY_SUFFIXES.include?(key) || %w[0 1].include?(key)
end
end
15 changes: 15 additions & 0 deletions spec/plural_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
plural_key: {
other: '%{count}'
}
},

explicit_0_1_rules: {
'0': 'zero',
'1': 'one',
other: '%{count}'
}
}
end
Expand Down Expand Up @@ -62,6 +68,15 @@
expect(depluralize('not_really_plural.one')).to eq('not_really_plural.one')
end

it 'does not ignore `0` and `1` explicit rules' do
expect(depluralize('explicit_0_1_rules.0')).to eq('explicit_0_1_rules.0')
expect(depluralize('explicit_0_1_rules.1')).to eq('explicit_0_1_rules.1')
end

it 'depluralizes keys that have explicit `0` and `1` rules siblings' do
expect(depluralize('explicit_0_1_rules.other')).to eq('explicit_0_1_rules')
end

def depluralize(key)
task.depluralize_key(key, 'en')
end
Expand Down

0 comments on commit ad846e1

Please sign in to comment.