https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292022-01-21T01:59:09ZRedmineRedmine - Defect #36461: I18nTest#test_custom_pluralization_rules randomly failshttps://www.redmine.org/issues/36461?journal_id=1053152022-01-21T01:59:09ZGo MAEDA
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/36396">Defect #36396</a>: Custom I18n Pluralization rules are not applied correctly</i> added</li></ul> Redmine - Defect #36461: I18nTest#test_custom_pluralization_rules randomly failshttps://www.redmine.org/issues/36461?journal_id=1053172022-01-21T05:59:43ZYuichi HARADA
<ul><li><strong>File</strong> <a href="/attachments/28714">36461.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/28714/36461.patch">36461.patch</a> added</li></ul><p>It seems that pluralization rules(config/locales/*.rb) is also loaded when loading the locale files located in I18n.load_path(<a class="source" href="https://www.redmine.org/projects/redmine/repository/svn/entry/trunk/config/application.rb#L42">source:/trunk/config/application.rb#L42</a>).</p>
<p><a class="external" href="https://github.com/ruby-i18n/i18n/wiki/Pluralizations">https://github.com/ruby-i18n/i18n/wiki/Pluralizations</a></p>
<blockquote>
<p>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.</p>
</blockquote>
<p>Therefore, it seems that you can't set pluralization rules in the middle like I18nTest#test_custom_pluralization_rules.<br />I have confirmed that the tests succeed with the following patch.</p>
<pre><code class="diff syntaxhl"><span class="gh">diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb
index 4e15ae56b7..f6e7a804d1 100644
</span><span class="gd">--- a/test/unit/lib/redmine/i18n_test.rb
</span><span class="gi">+++ b/test/unit/lib/redmine/i18n_test.rb
</span><span class="p">@@ -257,11 +257,13 @@</span> class Redmine::I18nTest < ActiveSupport::TestCase
end
def test_custom_pluralization_rules
<span class="gi">+ pluralizers = I18n.backend.instance_variable_get(:@pluralizers)
+ I18n.backend.instance_variable_set(:@pluralizers, nil)
</span> 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
<span class="gd">- I18n.reload!
</span><span class="gi">+ I18n.backend.instance_variable_set(:@pluralizers, pluralizers)
</span> end
end
</code></pre> Redmine - Defect #36461: I18nTest#test_custom_pluralization_rules randomly failshttps://www.redmine.org/issues/36461?journal_id=1053522022-01-22T09:17:00ZGo MAEDA
<ul><li><strong>Subject</strong> changed from <i>I18nTest#test_custom_pluralization_rules randomly fail</i> to <i>I18nTest#test_custom_pluralization_rules randomly fails</i></li><li><strong>Category</strong> set to <i>I18n</i></li><li><strong>Assignee</strong> set to <i>Go MAEDA</i></li><li><strong>Resolution</strong> set to <i>Fixed</i></li></ul><p>Committed the fix as a part of <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Defect: Custom I18n Pluralization rules are not applied correctly (Closed)" href="https://www.redmine.org/issues/36396">#36396</a>. Thank you.</p> Redmine - Defect #36461: I18nTest#test_custom_pluralization_rules randomly failshttps://www.redmine.org/issues/36461?journal_id=1055352022-02-03T04:07:23ZGo MAEDA
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Closed</i></li></ul>