From 09dc778eb26ca436f51f7be4cd6c0686b8d90530 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sat, 15 Jan 2022 03:18:33 +0000 Subject: [PATCH] Custom I18n Pluralization rules are not applied correctly (#36396). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Contributed by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@21365 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/i18n.rb | 4 ++-- test/unit/lib/redmine/i18n_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index 1e52439fc..b1066539f 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -159,14 +159,14 @@ module Redmine # * available_locales are determined by looking at translation file names class Backend < ::I18n::Backend::Simple module Implementation - include ::I18n::Backend::Pluralization - # Get available locales from the translations filenames def available_locales @available_locales ||= ::I18n.load_path.map {|path| File.basename(path, '.*')}.uniq.sort.map(&:to_sym) end end + # Adds custom pluralization rules + include ::I18n::Backend::Pluralization # Adds fallback to default locale for untranslated strings include ::I18n::Backend::Fallbacks end diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb index 4856c5190..4e15ae56b 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 :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! + end end -- 2.39.5