プロジェクト

全般

プロフィール

Vote #81792

完了

I18nTest#test_custom_pluralization_rules randomly fails

Admin Redmine さんがほぼ4年前に追加. ほぼ4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
I18n_37
対象バージョン:
-
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
37
version_id:
0
issue_org_id:
36461
author_id:
362529
assigned_to_id:
332
comments:
4
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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

journals

--------------------------------------------------------------------------------
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.

<pre><code class="diff">
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
</code></pre>
--------------------------------------------------------------------------------
Committed the fix as a part of #36396. Thank you.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,Closed,36396,Custom I18n Pluralization rules are not applied correctly

Admin Redmine さんがほぼ4年前に更新

  • カテゴリI18n_37 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0