From b92ad4fdeb09ada61db743be672391aa0069f207 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <[email protected]> Date: Tue, 26 Aug 2025 00:15:12 +0000 Subject: [PATCH 1/3] Initial plan From c54c36c7340cf8f3cfe91805a6a96786ccce8ab4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <[email protected]> Date: Tue, 26 Aug 2025 00:21:29 +0000 Subject: [PATCH 2/3] Add support for locale: '*' to use all available locales Co-authored-by: markets <[email protected]> --- lib/mini_i18n.rb | 10 ++++++++++ lib/mini_i18n/localization.rb | 10 ++++++++++ spec/localization_spec.rb | 19 +++++++++++++++++++ spec/mini_i18n_spec.rb | 5 +++++ 4 files changed, 44 insertions(+) diff --git a/lib/mini_i18n.rb b/lib/mini_i18n.rb index a867bd7..fb7fb0f 100644 --- a/lib/mini_i18n.rb +++ b/lib/mini_i18n.rb @@ -84,6 +84,8 @@ def translate(key, options = {}) return if key.empty? || translations.empty? return multiple_translate(key, options) if key.is_a?(Array) + + options = expand_all_locales(options) return multiple_locales(key, options) if options[:locale].is_a?(Array) _locale = available_locale?(options[:locale]) || locale @@ -172,5 +174,13 @@ def multiple_locales(key, options) t(key, options.merge(locale: _locale)) end end + + def expand_all_locales(options) + if options[:locale] == '*' + options.merge(locale: available_locales) + else + options + end + end end end diff --git a/lib/mini_i18n/localization.rb b/lib/mini_i18n/localization.rb index 0681037..a0c2318 100644 --- a/lib/mini_i18n/localization.rb +++ b/lib/mini_i18n/localization.rb @@ -9,6 +9,8 @@ module Localization def localize(object, options = {}) return multiple_localize(object, options) if object.is_a?(Array) + + options = expand_all_locales_localize(options) return multiple_locales_localize(object, options) if options[:locale].is_a?(Array) case object @@ -85,5 +87,13 @@ def multiple_locales_localize(object, options) localize(object, options.merge(locale: _locale)) end end + + def expand_all_locales_localize(options) + if options[:locale] == '*' + options.merge(locale: MiniI18n.available_locales) + else + options + end + end end end \ No newline at end of file diff --git a/spec/localization_spec.rb b/spec/localization_spec.rb index b16655b..2341a30 100644 --- a/spec/localization_spec.rb +++ b/spec/localization_spec.rb @@ -103,5 +103,24 @@ end end + describe 'all locales with *' do + let(:number) { 1234.56 } + + before do + # Ensure built-in locale data is loaded for proper formatting + MiniI18n.available_locales = [:en, :es, :fr] + end + + it 'localizes number for all locales' do + result = MiniI18n.l(number, locale: '*') + expect(result).to eq ['1,234.56', '1.234,56', '1 234,56'] + end + + it 'localizes with currency for all locales' do + result = MiniI18n.l(1000, as: :currency, locale: '*') + expect(result).to eq ['1,000 $', '1.000 €', nil] + end + end + end diff --git a/spec/mini_i18n_spec.rb b/spec/mini_i18n_spec.rb index 06bdcc0..4082cc5 100644 --- a/spec/mini_i18n_spec.rb +++ b/spec/mini_i18n_spec.rb @@ -76,6 +76,11 @@ expect(MiniI18n.t(:hello_interpolation, name: 'world', locale: [:en])).to eq ['hello world'] end + it "all locales with '*'" do + expect(MiniI18n.t(:hello, locale: '*')).to eq ['hello', 'hola', 'bonjour'] + expect(MiniI18n.t(:hello_interpolation, name: 'world', locale: '*')).to eq ['hello world', 'hola world', 'bonjour world'] + end + it "scope" do expect(MiniI18n.t('hello', scope: :second_level)).to eq 'hello 2' end From 3b42aaab6d46fa542a4bdcb39c1f9d529b334f2d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <[email protected]> Date: Tue, 26 Aug 2025 07:56:54 +0000 Subject: [PATCH 3/3] Remove duplicate expand_all_locales_localize method and update documentation Co-authored-by: markets <[email protected]> --- README.md | 10 ++++++++++ lib/mini_i18n/localization.rb | 10 +--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 963d15f..62d9d24 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ You can also use the long form methods: => "Hola" >> T(:hello, locale: [:en, :fr, :es]) => ["Hello", "Bonjour", "Hola"] +>> T(:hello, locale: '*') +=> ["Hello", "Hola", "Bonjour"] # Uses all available locales ``` **`scope`** @@ -339,6 +341,10 @@ dates = [Date.new(2023, 12, 25), Date.new(2024, 1, 1)] >> L(1234.56, locale: [:en, :es, :fr]) => ["1,234.56", "1.234,56", "1 234,56"] +# Use '*' to automatically include all available locales +>> L(1234.56, locale: '*') +=> ["1,234.56", "1.234,56", "1 234,56"] + # Localize date across different locales date = Date.new(2023, 8, 15) >> L(date, locale: [:en, :es, :de]) @@ -347,6 +353,10 @@ date = Date.new(2023, 8, 15) # Currency formatting across locales >> L(999.99, as: :currency, locale: [:en, :es, :de]) => ["999.99 $", "999,99 €", "999,99 €"] + +# Currency formatting for all available locales +>> L(1000, as: :currency, locale: '*') +=> ["1,000 $", "1.000 €", nil] # nil when locale doesn't have currency format ``` **Combining multiple objects and locales** diff --git a/lib/mini_i18n/localization.rb b/lib/mini_i18n/localization.rb index a0c2318..6d1477a 100644 --- a/lib/mini_i18n/localization.rb +++ b/lib/mini_i18n/localization.rb @@ -10,7 +10,7 @@ module Localization def localize(object, options = {}) return multiple_localize(object, options) if object.is_a?(Array) - options = expand_all_locales_localize(options) + options = expand_all_locales(options) return multiple_locales_localize(object, options) if options[:locale].is_a?(Array) case object @@ -87,13 +87,5 @@ def multiple_locales_localize(object, options) localize(object, options.merge(locale: _locale)) end end - - def expand_all_locales_localize(options) - if options[:locale] == '*' - options.merge(locale: MiniI18n.available_locales) - else - options - end - end end end \ No newline at end of file