Project

General

Profile

Actions

Defect #36461

closed

I18nTest#test_custom_pluralization_rules randomly fails

Added by Yuichi HARADA almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
I18n
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

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

36461.patch (887 Bytes) 36461.patch Yuichi HARADA, 2022-01-21 06:59

Related issues

Related to Redmine - Defect #36396: Custom I18n Pluralization rules are not applied correctlyClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA almost 3 years ago

  • Related to Defect #36396: Custom I18n Pluralization rules are not applied correctly added
Actions #2

Updated by Yuichi HARADA almost 3 years ago

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
Actions #3

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.

Actions #4

Updated by Go MAEDA almost 3 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF