Defect #36396

Custom I18n Pluralization rules are not applied correctly

Added by Felix Schäfer 11 months ago. Updated 11 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:I18n
Target version:5.0.0
Resolution:Fixed Affected version:4.2.3

Description

Currently custom pluralization rules are not loaded. This is due to the required ::I18n::Backend::Pluralization module not being loaded in the correct class.

36396-apply_custom_pluralization_rules.patch Magnifier (821 Bytes) Felix Schäfer, 2022-01-07 12:06


Related issues

Related to Redmine - Defect #21856: I18n backend does not support original i18n Pluralization Closed
Related to Redmine - Defect #36461: I18nTest#test_custom_pluralization_rules randomly fails Closed

Associated revisions

Revision 21365
Added by Go MAEDA 11 months ago

Custom I18n Pluralization rules are not applied correctly (#36396).

Contributed by Felix Schäfer.

Revision 21382
Added by Go MAEDA 11 months ago

Fix that I18nTest#test_custom_pluralization_rules randomly fails (#36396, #36461).

Patch by Yuichi HARADA.

History

#1 Updated by Felix Schäfer 11 months ago

The attached Patch changes the inclusion of ::I18n::Backend::Pluralization to the correct class.

#2 Updated by Go MAEDA 11 months ago

  • Related to Defect #21856: I18n backend does not support original i18n Pluralization added

#3 Updated by Go MAEDA 11 months ago

Felix, do you think the following code I wrote properly tests the issue?

diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb
index 4856c5190..8d076a385 100644
--- a/test/unit/lib/redmine/i18n_test.rb
+++ b/test/unit/lib/redmine/i18n_test.rb
@@ -255,4 +255,13 @@ class Redmine::I18nTest < ActiveSupport::TestCase
     set_language_if_valid 'fr'
     assert_equal 'French (Français)', l(:general_lang_name)
   end
+
+  def test_custom_pluralization_rules
+    I18n.backend.store_translations :en, i18n: {plural: {rule: ->(n) {[0, 1].include?(n) ? :one : :other }}}
+    I18n.backend.store_translations :en, apples: {one: 'one or none', other: 'more than one'}
+    assert_equal 'one or none', ll(:en, :apples, count: 0)
+    assert_equal 'more than one', ll(:en, :apples, count: 2)
+  ensure
+    I18n.reload!
+  end
 end

#4 Updated by Go MAEDA 11 months ago

  • Category changed from Translations to I18n

#5 Updated by Felix Schäfer 11 months ago

Go MAEDA wrote:

Felix, do you think the following code I wrote properly tests the issue?

Thank you very much for the suggestion. The proposed test should catch a misconfiguration of the `::I18n::Backend::Pluralization` backend in `::Redmine::I18n`.

#6 Updated by Go MAEDA 11 months ago

  • Target version set to 4.1.6

Setting the target version to 4.1.6.

#7 Updated by Go MAEDA 11 months ago

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix. Thank you.

#8 Updated by Go MAEDA 11 months ago

  • Related to Defect #36461: I18nTest#test_custom_pluralization_rules randomly fails added

#9 Updated by Go MAEDA 11 months ago

  • Status changed from Resolved to Closed
  • Target version changed from 4.1.6 to 5.0.0

Also available in: Atom PDF