mini_i18n 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cb5cf9833c1d4bfb7f45fed780cd5207ae00b1b51d9f2f5c53bd3239675920b
4
- data.tar.gz: 8bc35757a1d45205133ffd112c1681698629d01faac6e846805c9f970673e57f
3
+ metadata.gz: 0ea63c599641e26606871bd18ce2b243f98dffe687f450ce2e77e496b220844f
4
+ data.tar.gz: 1471da8e960833faa66922d65d5e1fa391ec35e2c4d25f9261fca358316f6d2c
5
5
  SHA512:
6
- metadata.gz: d0e50f36c05e3857048ea02754c0c5794d2bae63d3524153adbcaeea16b00c080784317051994930fd4a19ca7bd42e5a4d24fbf21ec2b7227f73a6b872817c71
7
- data.tar.gz: 567b252d2c586e3b7678f3f7ce19e89195cf665a685141eba42bd259a6a09c26c353717f8f2fc232225547aa3f43ef495606cd3fa780aef96400cebaf5fe865b
6
+ metadata.gz: 3cee5c6b4037553fba77cbd85acc49b3e20807b705041d97cd79ac1478b7e5d90eaf42f27503da0f0c45251ed3aa7464818f762eeb7fd71382691ae71a0bf6f6
7
+ data.tar.gz: 82c821f400ff2a53d2b3a07dbaf6dc1e67314276e1ed04427ad5a1d6984bc6b1c87a2cb8d5f4f53bf7b3b43a38aa79b1aed9a18ab285430ccb46cdebcfd3abf9
@@ -0,0 +1,17 @@
1
+ ar:
2
+ date:
3
+ formats:
4
+ default: "%A %-d %B %Y"
5
+ short: "%d/%m/%y"
6
+ day_names: [الأحد, الاثنين, الثلاثاء, الأربعاء, الخميس, الجمعة, السبت]
7
+ abbr_day_names: [أحد, اثن, ثلا, أرب, خمي, جمع, سبت]
8
+ month_names: [يناير, فبراير, مارس, أبريل, مايو, يونيو, يوليو, أغسطس, سبتمبر, أكتوبر, نوفمبر, ديسمبر]
9
+ abbr_month_names: [ينا, فبر, مار, أبر, ماي, يون, يول, أغس, سبت, أكت, نوف, ديس]
10
+ time:
11
+ formats:
12
+ default: "%a %-d %B %Y - %H:%M"
13
+ short: "%d/%m/%y - %H:%M"
14
+ number:
15
+ format:
16
+ delimiter: ','
17
+ separator: '.'
@@ -0,0 +1,17 @@
1
+ ru:
2
+ date:
3
+ formats:
4
+ default: "%A, %-d %B %Y г."
5
+ short: "%d.%m.%y"
6
+ day_names: [воскресенье, понедельник, вторник, среда, четверг, пятница, суббота]
7
+ abbr_day_names: [вс, пн, вт, ср, чт, пт, сб]
8
+ month_names: [январь, февраль, март, апрель, май, июнь, июль, август, сентябрь, октябрь, ноябрь, декабрь]
9
+ abbr_month_names: [янв, фев, мар, апр, май, июн, июл, авг, сен, окт, ноя, дек]
10
+ time:
11
+ formats:
12
+ default: "%a, %-d %B %Y г. - %H:%M"
13
+ short: "%d.%m.%y - %H:%M"
14
+ number:
15
+ format:
16
+ delimiter: ' '
17
+ separator: ','
@@ -8,6 +8,11 @@ module MiniI18n
8
8
  DAYS_MONTHS_REGEX = /%[aAbB]/
9
9
 
10
10
  def localize(object, options = {})
11
+ return multiple_localize(object, options) if object.is_a?(Array)
12
+
13
+ options = expand_all_locales(options)
14
+ return multiple_locales_localize(object, options) if options[:locale].is_a?(Array)
15
+
11
16
  case object
12
17
  when Numeric
13
18
  localize_number(object, options)
@@ -70,5 +75,17 @@ module MiniI18n
70
75
 
71
76
  object && localize(object, options)
72
77
  end
78
+
79
+ def multiple_localize(objects, options)
80
+ objects.map do |obj|
81
+ localize(obj, options)
82
+ end
83
+ end
84
+
85
+ def multiple_locales_localize(object, options)
86
+ options[:locale].map do |_locale|
87
+ localize(object, options.merge(locale: _locale))
88
+ end
89
+ end
73
90
  end
74
91
  end
@@ -8,7 +8,7 @@ module MiniI18n
8
8
  private
9
9
 
10
10
  def self.default_rule
11
- -> (n) {
11
+ @default_rule ||= -> (n) {
12
12
  case n
13
13
  when 0
14
14
  'zero'
@@ -20,4 +20,4 @@ module MiniI18n
20
20
  }
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -9,15 +9,15 @@ module MiniI18n
9
9
  end
10
10
 
11
11
  def deep_merge(merge_to, merge_from)
12
- merged = merge_to.clone
12
+ merged = merge_to.dup
13
13
 
14
14
  merge_from.each do |key, value|
15
- key = key.to_s
15
+ string_key = key.to_s
16
16
 
17
- if value.is_a?(Hash) && merged[key].is_a?(Hash)
18
- merged[key] = deep_merge(merged[key], value)
17
+ if value.is_a?(Hash) && merged[string_key].is_a?(Hash)
18
+ merged[string_key] = deep_merge(merged[string_key], value)
19
19
  else
20
- merged[key] = value
20
+ merged[string_key] = value
21
21
  end
22
22
  end
23
23
 
@@ -1,3 +1,3 @@
1
1
  module MiniI18n
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/mini_i18n.rb CHANGED
@@ -84,15 +84,16 @@ module MiniI18n
84
84
  return if key.empty? || translations.empty?
85
85
 
86
86
  return multiple_translate(key, options) if key.is_a?(Array)
87
+
88
+ options = expand_all_locales(options)
87
89
  return multiple_locales(key, options) if options[:locale].is_a?(Array)
88
90
 
89
91
  _locale = available_locale?(options[:locale]) || locale
90
92
  scope = options[:scope]
91
93
 
92
94
  keys = [_locale.to_s]
93
- keys << scope.to_s.split(separator) if scope
94
- keys << key.to_s.split(separator)
95
- keys = keys.flatten
95
+ keys.concat(scope.to_s.split(separator)) if scope
96
+ keys.concat(key.to_s.split(separator))
96
97
 
97
98
  result = lookup(*keys)
98
99
 
@@ -117,8 +118,8 @@ module MiniI18n
117
118
  end
118
119
 
119
120
  def available_locale?(new_locale)
120
- new_locale = new_locale.to_s
121
- available_locales.include?(new_locale) && new_locale
121
+ locale_string = new_locale.to_s
122
+ available_locales.include?(locale_string) && locale_string
122
123
  end
123
124
 
124
125
  def lookup(*keys)
@@ -155,7 +156,7 @@ module MiniI18n
155
156
  end
156
157
 
157
158
  def with_interpolation(result, options)
158
- if result.respond_to?(:match) && result.match(/%{\w+}/)
159
+ if result.is_a?(String) && result.include?('%{')
159
160
  result = Utils.interpolate(result, options)
160
161
  end
161
162
 
@@ -173,5 +174,13 @@ module MiniI18n
173
174
  t(key, options.merge(locale: _locale))
174
175
  end
175
176
  end
177
+
178
+ def expand_all_locales(options)
179
+ if options[:locale] == '*'
180
+ options.merge(locale: available_locales)
181
+ else
182
+ options
183
+ end
184
+ end
176
185
  end
177
186
  end
@@ -6,7 +6,7 @@ RSpec.describe "Default Locales Integration" do
6
6
  before(:each) do
7
7
  @original_translations = MiniI18n.translations.dup
8
8
  @original_available_locales = MiniI18n.available_locales.dup
9
- MiniI18n.available_locales = [:en, :es, :fr, :de, :pt, :it, :nl, :zh, :ja]
9
+ MiniI18n.available_locales = [:en, :es, :fr, :de, :pt, :it, :nl, :zh, :ja, :ru, :ar]
10
10
  end
11
11
 
12
12
  after(:each) do
@@ -26,6 +26,8 @@ RSpec.describe "Default Locales Integration" do
26
26
  expect(MiniI18n.l(date, locale: :nl)).to eq("maandag 25 december 2023")
27
27
  expect(MiniI18n.l(date, locale: :zh)).to eq("2023年12月25日")
28
28
  expect(MiniI18n.l(date, locale: :ja)).to eq("2023年12月25日(月)")
29
+ expect(MiniI18n.l(date, locale: :ru)).to eq("понедельник, 25 декабрь 2023 г.")
30
+ expect(MiniI18n.l(date, locale: :ar)).to eq("الاثنين 25 ديسمبر 2023")
29
31
  end
30
32
 
31
33
  it "formats short dates according to each locale" do
@@ -38,6 +40,8 @@ RSpec.describe "Default Locales Integration" do
38
40
  expect(MiniI18n.l(date, format: :short, locale: :nl)).to eq("25-12-23")
39
41
  expect(MiniI18n.l(date, format: :short, locale: :zh)).to eq("12月25日")
40
42
  expect(MiniI18n.l(date, format: :short, locale: :ja)).to eq("12/25")
43
+ expect(MiniI18n.l(date, format: :short, locale: :ru)).to eq("25.12.23")
44
+ expect(MiniI18n.l(date, format: :short, locale: :ar)).to eq("25/12/23")
41
45
  end
42
46
  end
43
47
 
@@ -52,6 +56,8 @@ RSpec.describe "Default Locales Integration" do
52
56
  expect(MiniI18n.l(time, locale: :nl)).to eq("ma 25 december 2023 - 14:30")
53
57
  expect(MiniI18n.l(time, locale: :zh)).to eq("2023年12月25日 星期一 14:30")
54
58
  expect(MiniI18n.l(time, locale: :ja)).to eq("2023年12月25日(月) 14時30分")
59
+ expect(MiniI18n.l(time, locale: :ru)).to eq("пн, 25 декабрь 2023 г. - 14:30")
60
+ expect(MiniI18n.l(time, locale: :ar)).to eq("اثن 25 ديسمبر 2023 - 14:30")
55
61
  end
56
62
  end
57
63
 
@@ -66,6 +72,8 @@ RSpec.describe "Default Locales Integration" do
66
72
  expect(MiniI18n.l(number, locale: :nl)).to eq("1.234,56")
67
73
  expect(MiniI18n.l(number, locale: :zh)).to eq("1,234.56")
68
74
  expect(MiniI18n.l(number, locale: :ja)).to eq("1,234.56")
75
+ expect(MiniI18n.l(number, locale: :ru)).to eq("1 234,56")
76
+ expect(MiniI18n.l(number, locale: :ar)).to eq("1,234.56")
69
77
  end
70
78
  end
71
79
  end
@@ -46,4 +46,79 @@ RSpec.describe MiniI18n::Localization do
46
46
  expect(MiniI18n.l(125.5, as: :distance)).to eq 'Distance -> 125.5 miles'
47
47
  end
48
48
  end
49
+
50
+ describe 'multiple objects' do
51
+ let(:date) { Date.new(2018, 8, 7) }
52
+ let(:number) { 1234.56 }
53
+
54
+ it 'localizes multiple objects with same options' do
55
+ result = MiniI18n.l([date, number])
56
+ expect(result).to eq ['Tuesday 07, August, 2018', '1,234.56']
57
+ end
58
+
59
+ it 'localizes multiple objects with specific locale' do
60
+ result = MiniI18n.l([number, 9000], locale: :es)
61
+ expect(result).to eq ['1.234,56', '9.000']
62
+ end
63
+
64
+ it 'localizes multiple objects with different formats' do
65
+ result = MiniI18n.l([date, time], format: :short)
66
+ expect(result).to eq ['07 Aug 18', '07 Aug 18 - 22:30']
67
+ end
68
+
69
+ it 'localizes multiple objects with as option' do
70
+ result = MiniI18n.l([1000, 2000], as: :currency)
71
+ expect(result).to eq ['1,000 $', '2,000 $']
72
+ end
73
+ end
74
+
75
+ describe 'multiple locales' do
76
+ let(:number) { 1234.56 }
77
+
78
+ it 'localizes same object for multiple locales' do
79
+ result = MiniI18n.l(number, locale: [:en, :es])
80
+ expect(result).to eq ['1,234.56', '1.234,56']
81
+ end
82
+
83
+ it 'localizes date for multiple locales' do
84
+ date = Date.new(2018, 8, 7)
85
+ result = MiniI18n.l(date, locale: [:en, :es])
86
+ expect(result).to eq ['Tuesday 07, August, 2018', '7/8/2018']
87
+ end
88
+
89
+ it 'localizes time for multiple locales' do
90
+ result = MiniI18n.l(time, locale: [:en, :es])
91
+ expect(result).to eq ['Tue 07, August, 2018 - 22:30', 'mar 7 de agosto de 2018 - 22:30']
92
+ end
93
+
94
+ it 'localizes number with currency for multiple locales' do
95
+ result = MiniI18n.l(1000, as: :currency, locale: [:en, :es])
96
+ expect(result).to eq ['1,000 $', '1.000 €']
97
+ end
98
+
99
+ it 'localizes with format for multiple locales' do
100
+ date = Date.new(2018, 8, 7)
101
+ result = MiniI18n.l(date, format: :short, locale: [:en, :es])
102
+ expect(result).to eq ['07 Aug 18', '7 ago 18']
103
+ end
104
+ end
105
+
106
+ describe 'all locales with *' do
107
+ let(:number) { 1234.56 }
108
+
109
+ before do
110
+ # Ensure built-in locale data is loaded for proper formatting
111
+ MiniI18n.available_locales = [:en, :es, :fr]
112
+ end
113
+
114
+ it 'localizes number for all locales' do
115
+ result = MiniI18n.l(number, locale: '*')
116
+ expect(result).to eq ['1,234.56', '1.234,56', '1 234,56']
117
+ end
118
+
119
+ it 'localizes with currency for all locales' do
120
+ result = MiniI18n.l(1000, as: :currency, locale: '*')
121
+ expect(result).to eq ['1,000 $', '1.000 €', nil]
122
+ end
123
+ end
49
124
  end
@@ -76,6 +76,10 @@ RSpec.describe MiniI18n do
76
76
  expect(MiniI18n.t(:hello_interpolation, name: 'world', locale: [:en])).to eq ['hello world']
77
77
  end
78
78
 
79
+ it "all locales with '*'" do
80
+ expect(MiniI18n.t(:hello, locale: '*')).to eq ['hello', 'hola', 'bonjour']
81
+ end
82
+
79
83
  it "scope" do
80
84
  expect(MiniI18n.t('hello', scope: :second_level)).to eq 'hello 2'
81
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-15 00:00:00.000000000 Z
11
+ date: 2025-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - lib/mini_i18n.rb
78
78
  - lib/mini_i18n/kernel_extensions.rb
79
+ - lib/mini_i18n/locales/ar.yml
79
80
  - lib/mini_i18n/locales/de.yml
80
81
  - lib/mini_i18n/locales/en.yml
81
82
  - lib/mini_i18n/locales/es.yml
@@ -84,6 +85,7 @@ files:
84
85
  - lib/mini_i18n/locales/ja.yml
85
86
  - lib/mini_i18n/locales/nl.yml
86
87
  - lib/mini_i18n/locales/pt.yml
88
+ - lib/mini_i18n/locales/ru.yml
87
89
  - lib/mini_i18n/locales/zh.yml
88
90
  - lib/mini_i18n/localization.rb
89
91
  - lib/mini_i18n/pluralization.rb