Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 25, 2025

Implements support for multiple objects and multiple locales in the localize method, bringing it to feature parity with the existing translate method functionality.

Problem

The translate method supports both multiple keys and multiple locales:

# Multiple keys
MiniI18n.t([:hello, :bye]) #=> ['hello', 'bye']

# Multiple locales  
MiniI18n.t(:hello, locale: [:en, :es, :fr]) #=> ['hello', 'hola', 'bonjour']

However, the localize method only supported single objects and single locales, limiting its flexibility for batch operations.

Solution

Added the same multiple object and multiple locale capabilities to the localize method:

# Multiple objects
date = Date.new(2023, 12, 25)
number = 1234.56
MiniI18n.l([date, number]) 
#=> ["Monday 25, December, 2023", "1,234.56"]

# Multiple locales
MiniI18n.l(number, locale: [:en, :es, :fr])
#=> ["1,234.56", "1.234,56", "1 234,56"]

# Works with existing options
MiniI18n.l([1000, 2000], as: :currency, locale: :es)
#=> ["1.000 €", "2.000 €"]

Implementation

  • Added early return logic in localize method to detect arrays
  • Implemented multiple_localize and multiple_locales_localize helper methods following the same pattern as the translate method
  • Maintains full backward compatibility - all existing functionality preserved
  • Works with both localize and l alias methods
  • Supports all existing options (format, as, type, etc.)

Testing

  • Added comprehensive test coverage for both multiple objects and multiple locales scenarios
  • All 45 tests pass (43 existing + 2 new)
  • Tested with all built-in locales and edge cases
  • Integration tests confirm compatibility with existing locale data

This change enables more efficient batch localization operations while maintaining the library's existing API and behavior.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Like we have multiple translations and multiple locales in the translate method, lets implement the same for the localize method Add multiple objects and multiple locales support to localize method Aug 25, 2025
Copilot AI requested a review from markets August 25, 2025 23:47
Copilot AI requested a review from markets August 25, 2025 23:57
@markets
Copy link
Owner

markets commented Aug 25, 2025

@copilot moven the docs under the localization section and expand with more examples

Copy link
Contributor Author

Copilot AI commented Aug 26, 2025

@copilot moven the docs under the localization section and expand with more examples

Moved the documentation to the localization section and expanded it with comprehensive examples covering multiple dates, numbers, currency formatting across locales, and combinations of both multiple objects and multiple locales. The examples now include proper formatting options and demonstrate real-world use cases. Changes in commit 81471d1.

@markets markets marked this pull request as ready for review August 26, 2025 00:10
@markets markets merged commit 85f888a into master Aug 26, 2025
8 checks passed
@markets markets deleted the copilot/fix-426fd518-cd1a-4f53-94d8-1ea913a0bb13 branch August 26, 2025 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants