Defect #36461
closedI18nTest#test_custom_pluralization_rules randomly fails
0%
Description
The test will be always failed if the following conditions are met:
- using trunk(r21372)
- Run the test specified a seed value(
TESTOPTS="--seed 46869"
)
% RAILS_ENV=test bundle exec rake db:migrate:reset % RAILS_ENV=test bundle exec rake test TESTOPTS="--seed 46869" (Test LDAP server not configured) Bazaar non ASCII output test cannot run on this environment. Encoding.locale_charmap: UTF-8 Skipping LDAP tests. Run options: --seed 46869 # Running: .................F Failure: Redmine::I18nTest#test_custom_pluralization_rules [test/unit/lib/redmine/i18n_test.rb:262]: Expected: "one or none" Actual: "more than one" rails test test/unit/lib/redmine/i18n_test.rb:259
Files
Related issues
Updated by Go MAEDA almost 3 years ago
- Related to Defect #36396: Custom I18n Pluralization rules are not applied correctly added
Updated by Yuichi HARADA almost 3 years ago
- File 36461.patch 36461.patch added
It seems that pluralization rules(config/locales/*.rb) is also loaded when loading the locale files located in I18n.load_path(source:/trunk/config/application.rb#L42).
https://github.com/ruby-i18n/i18n/wiki/Pluralizations
One can ship pluralizers (i.e. lambdas that implement locale specific pluralization algorithms) as part of any Ruby translation file anywhere in the I18n.load_path. The implementation expects to find them with the key :pluralize in a (newly invented) translation metadata namespace :i18n.
Therefore, it seems that you can't set pluralization rules in the middle like I18nTest#test_custom_pluralization_rules.
I have confirmed that the tests succeed with the following patch.
diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb
index 4e15ae56b7..f6e7a804d1 100644
--- a/test/unit/lib/redmine/i18n_test.rb
+++ b/test/unit/lib/redmine/i18n_test.rb
@@ -257,11 +257,13 @@ class Redmine::I18nTest < ActiveSupport::TestCase
end
def test_custom_pluralization_rules
+ pluralizers = I18n.backend.instance_variable_get(:@pluralizers)
+ I18n.backend.instance_variable_set(:@pluralizers, nil)
I18n.backend.store_translations :pt, i18n: {plural: {rule: ->(n) {[0, 1].include?(n) ? :one : :other }}}
I18n.backend.store_translations :pt, apples: {one: 'one or none', other: 'more than one'}
assert_equal 'one or none', ll(:pt, :apples, count: 0)
assert_equal 'more than one', ll(:pt, :apples, count: 2)
ensure
- I18n.reload!
+ I18n.backend.instance_variable_set(:@pluralizers, pluralizers)
end
end
Updated by Go MAEDA almost 3 years ago
- Subject changed from I18nTest#test_custom_pluralization_rules randomly fail to I18nTest#test_custom_pluralization_rules randomly fails
- Category set to I18n
- Assignee set to Go MAEDA
- Resolution set to Fixed
Committed the fix as a part of #36396. Thank you.