From 74b5e399a38fac0bbb8f03fb9c75638748dab430 Mon Sep 17 00:00:00 2001 From: Ali Ismayilov <993934+aliismayilov@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:09:30 +0100 Subject: [PATCH] Offer case locale specific case manipulation --- lib/i18n.rb | 16 ++++++++++++++++ test/i18n_test.rb | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/i18n.rb b/lib/i18n.rb index 578a5969..d4917197 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -388,6 +388,22 @@ def available_locales_initialized? config.available_locales_initialized? end + def capitalize(string, locale: nil, rules: t(:'i18n.case_map.rules', locale:, default: nil)) + string.capitalize(*rules) + end + + def downcase(string, locale: nil, rules: t(:'i18n.case_map.rules', locale:, default: nil)) + string.downcase(*rules) + end + + def swapcase(string, locale: nil, rules: t(:'i18n.case_map.rules', locale:, default: nil)) + string.swapcase(*rules) + end + + def upcase(string, locale: nil, rules: t(:'i18n.case_map.rules', locale:, default: nil)) + string.upcase(*rules) + end + private def translate_key(key, throw, raise, locale, backend, options) diff --git a/test/i18n_test.rb b/test/i18n_test.rb index 90077147..436e1361 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -455,6 +455,23 @@ def call(exception, locale, key, options); key; end assert_equal "???", I18n.transliterate("日本語") end + test "upcase string" do + assert_equal "TÜRKIYE", I18n.upcase("Türkiye") + end + + test "upcase string with locale" do + assert_equal "TÜRKIYE", I18n.upcase("Türkiye", locale: nil) + end + + test "upcase string with rules" do + assert_equal "TÜRKİYE", I18n.upcase("Türkiye", rules: :turkic) + end + + test "upcase string with stored rules" do + store_translations(:tr, {i18n: {case_map: {rules: [:turkic]}}}) + assert_equal "TÜRKİYE", I18n.upcase("Türkiye", locale: :tr) + end + test "I18n.locale_available? returns true when the passed locale is available" do I18n.available_locales = [:en, :de] assert_equal true, I18n.locale_available?(:de)