mini_i18n 0.9.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 +4 -4
- data/lib/mini_i18n/kernel_extensions.rb +11 -0
- data/lib/mini_i18n/locales/ar.yml +17 -0
- data/lib/mini_i18n/locales/de.yml +17 -0
- data/{spec/fixtures/locales/localization.yml → lib/mini_i18n/locales/en.yml} +0 -3
- data/lib/mini_i18n/locales/es.yml +17 -0
- data/lib/mini_i18n/locales/fr.yml +17 -0
- data/lib/mini_i18n/locales/it.yml +17 -0
- data/lib/mini_i18n/locales/ja.yml +17 -0
- data/lib/mini_i18n/locales/nl.yml +17 -0
- data/lib/mini_i18n/locales/pt.yml +17 -0
- data/lib/mini_i18n/locales/ru.yml +17 -0
- data/lib/mini_i18n/locales/zh.yml +17 -0
- data/lib/mini_i18n/localization.rb +18 -1
- data/lib/mini_i18n/pluralization.rb +2 -2
- data/lib/mini_i18n/utils.rb +5 -5
- data/lib/mini_i18n/version.rb +1 -1
- data/lib/mini_i18n.rb +26 -6
- data/spec/default_locales_integration_spec.rb +79 -0
- data/spec/fixtures/locales/en.yml +5 -1
- data/spec/kernel_extensions_spec.rb +24 -0
- data/spec/localization_spec.rb +78 -3
- data/spec/mini_i18n_spec.rb +4 -0
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ea63c599641e26606871bd18ce2b243f98dffe687f450ce2e77e496b220844f
|
4
|
+
data.tar.gz: 1471da8e960833faa66922d65d5e1fa391ec35e2c4d25f9261fca358316f6d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
de:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%A, %-d. %B %Y"
|
5
|
+
short: "%-d.%-m.%y"
|
6
|
+
day_names: [Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag]
|
7
|
+
abbr_day_names: [So, Mo, Di, Mi, Do, Fr, Sa]
|
8
|
+
month_names: [Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember]
|
9
|
+
abbr_month_names: [Jan, Feb, Mär, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez]
|
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
|
+
es:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%-d/%-m/%Y"
|
5
|
+
short: "%-d %b %y"
|
6
|
+
day_names: [domingo, lunes, martes, miércoles, jueves, viernes, sábado]
|
7
|
+
abbr_day_names: [dom, lun, mar, mié, jue, vie, sáb]
|
8
|
+
month_names: [enero, febrero, marzo, abril, mayo, junio, julio, agosto, septiembre, octubre, noviembre, diciembre]
|
9
|
+
abbr_month_names: [ene, feb, mar, abr, may, jun, jul, ago, sep, oct, nov, dic]
|
10
|
+
time:
|
11
|
+
formats:
|
12
|
+
default: "%a %-d de %B de %Y - %H:%M"
|
13
|
+
short: "%-d %b %y - %H:%M"
|
14
|
+
number:
|
15
|
+
format:
|
16
|
+
delimiter: '.'
|
17
|
+
separator: ','
|
@@ -0,0 +1,17 @@
|
|
1
|
+
fr:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%A %-d %B %Y"
|
5
|
+
short: "%-d %b %y"
|
6
|
+
day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi]
|
7
|
+
abbr_day_names: [dim, lun, mar, mer, jeu, ven, sam]
|
8
|
+
month_names: [janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre]
|
9
|
+
abbr_month_names: [janv, févr, mars, avr, mai, juin, juil, août, sept, oct, nov, déc]
|
10
|
+
time:
|
11
|
+
formats:
|
12
|
+
default: "%a %-d %B %Y - %H:%M"
|
13
|
+
short: "%-d %b %y - %H:%M"
|
14
|
+
number:
|
15
|
+
format:
|
16
|
+
delimiter: ' '
|
17
|
+
separator: ','
|
@@ -0,0 +1,17 @@
|
|
1
|
+
it:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%A %-d %B %Y"
|
5
|
+
short: "%-d/%m/%y"
|
6
|
+
day_names: [domenica, lunedì, martedì, mercoledì, giovedì, venerdì, sabato]
|
7
|
+
abbr_day_names: [dom, lun, mar, mer, gio, ven, sab]
|
8
|
+
month_names: [gennaio, febbraio, marzo, aprile, maggio, giugno, luglio, agosto, settembre, ottobre, novembre, dicembre]
|
9
|
+
abbr_month_names: [gen, feb, mar, apr, mag, giu, lug, ago, set, ott, nov, dic]
|
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
|
+
ja:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%Y年%m月%d日(%a)"
|
5
|
+
short: "%m/%d"
|
6
|
+
day_names: [日曜日, 月曜日, 火曜日, 水曜日, 木曜日, 金曜日, 土曜日]
|
7
|
+
abbr_day_names: [日, 月, 火, 水, 木, 金, 土]
|
8
|
+
month_names: [1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
|
9
|
+
abbr_month_names: [1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
|
10
|
+
time:
|
11
|
+
formats:
|
12
|
+
default: "%Y年%m月%d日(%a) %H時%M分"
|
13
|
+
short: "%m/%d %H:%M"
|
14
|
+
number:
|
15
|
+
format:
|
16
|
+
delimiter: ','
|
17
|
+
separator: '.'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
nl:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%A %-d %B %Y"
|
5
|
+
short: "%-d-%-m-%y"
|
6
|
+
day_names: [zondag, maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag]
|
7
|
+
abbr_day_names: [zo, ma, di, wo, do, vr, za]
|
8
|
+
month_names: [januari, februari, maart, april, mei, juni, juli, augustus, september, oktober, november, december]
|
9
|
+
abbr_month_names: [jan, feb, mrt, apr, mei, jun, jul, aug, sep, okt, nov, dec]
|
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
|
+
pt:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%A, %-d de %B de %Y"
|
5
|
+
short: "%-d/%m/%y"
|
6
|
+
day_names: [domingo, segunda-feira, terça-feira, quarta-feira, quinta-feira, sexta-feira, sábado]
|
7
|
+
abbr_day_names: [dom, seg, ter, qua, qui, sex, sáb]
|
8
|
+
month_names: [janeiro, fevereiro, março, abril, maio, junho, julho, agosto, setembro, outubro, novembro, dezembro]
|
9
|
+
abbr_month_names: [jan, fev, mar, abr, mai, jun, jul, ago, set, out, nov, dez]
|
10
|
+
time:
|
11
|
+
formats:
|
12
|
+
default: "%a, %-d de %B de %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: ','
|
@@ -0,0 +1,17 @@
|
|
1
|
+
zh:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%Y年%m月%d日"
|
5
|
+
short: "%m月%d日"
|
6
|
+
day_names: [星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六]
|
7
|
+
abbr_day_names: [周日, 周一, 周二, 周三, 周四, 周五, 周六]
|
8
|
+
month_names: [一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
|
9
|
+
abbr_month_names: [1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
|
10
|
+
time:
|
11
|
+
formats:
|
12
|
+
default: "%Y年%m月%d日 %A %H:%M"
|
13
|
+
short: "%m月%d日 %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)
|
@@ -27,7 +32,7 @@ module MiniI18n
|
|
27
32
|
locale = options[:locale]
|
28
33
|
delimiter = MiniI18n.t("number.format.delimiter", locale: locale)
|
29
34
|
separator = MiniI18n.t("number.format.separator", locale: locale)
|
30
|
-
integer, fractional = number.to_s.split(
|
35
|
+
integer, fractional = number.to_s.split('.')
|
31
36
|
|
32
37
|
integer.to_s.gsub!(DELIMITER_REGEX) do |match|
|
33
38
|
"#{match}#{delimiter}"
|
@@ -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
|
data/lib/mini_i18n/utils.rb
CHANGED
@@ -9,15 +9,15 @@ module MiniI18n
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def deep_merge(merge_to, merge_from)
|
12
|
-
merged = merge_to.
|
12
|
+
merged = merge_to.dup
|
13
13
|
|
14
14
|
merge_from.each do |key, value|
|
15
|
-
|
15
|
+
string_key = key.to_s
|
16
16
|
|
17
|
-
if value.is_a?(Hash) && merged[
|
18
|
-
merged[
|
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[
|
20
|
+
merged[string_key] = value
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/lib/mini_i18n/version.rb
CHANGED
data/lib/mini_i18n.rb
CHANGED
@@ -3,6 +3,7 @@ require "mini_i18n/version"
|
|
3
3
|
require "mini_i18n/utils"
|
4
4
|
require "mini_i18n/localization"
|
5
5
|
require "mini_i18n/pluralization"
|
6
|
+
require "mini_i18n/kernel_extensions"
|
6
7
|
|
7
8
|
module MiniI18n
|
8
9
|
class << self
|
@@ -27,6 +28,16 @@ module MiniI18n
|
|
27
28
|
|
28
29
|
def available_locales=(new_locales)
|
29
30
|
@@available_locales = Array(new_locales).map(&:to_s)
|
31
|
+
|
32
|
+
# Load built-in localization defaults
|
33
|
+
@@available_locales.each do |locale|
|
34
|
+
default_locale_path = File.join(File.dirname(__FILE__), "mini_i18n", "locales", "#{locale}.yml")
|
35
|
+
if File.exist?(default_locale_path)
|
36
|
+
YAML.load_file(default_locale_path).each do |loc, translations|
|
37
|
+
add_translations(loc, translations)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
30
41
|
end
|
31
42
|
|
32
43
|
def translations
|
@@ -73,15 +84,16 @@ module MiniI18n
|
|
73
84
|
return if key.empty? || translations.empty?
|
74
85
|
|
75
86
|
return multiple_translate(key, options) if key.is_a?(Array)
|
87
|
+
|
88
|
+
options = expand_all_locales(options)
|
76
89
|
return multiple_locales(key, options) if options[:locale].is_a?(Array)
|
77
90
|
|
78
91
|
_locale = available_locale?(options[:locale]) || locale
|
79
92
|
scope = options[:scope]
|
80
93
|
|
81
94
|
keys = [_locale.to_s]
|
82
|
-
keys
|
83
|
-
keys
|
84
|
-
keys = keys.flatten
|
95
|
+
keys.concat(scope.to_s.split(separator)) if scope
|
96
|
+
keys.concat(key.to_s.split(separator))
|
85
97
|
|
86
98
|
result = lookup(*keys)
|
87
99
|
|
@@ -106,8 +118,8 @@ module MiniI18n
|
|
106
118
|
end
|
107
119
|
|
108
120
|
def available_locale?(new_locale)
|
109
|
-
|
110
|
-
available_locales.include?(
|
121
|
+
locale_string = new_locale.to_s
|
122
|
+
available_locales.include?(locale_string) && locale_string
|
111
123
|
end
|
112
124
|
|
113
125
|
def lookup(*keys)
|
@@ -144,7 +156,7 @@ module MiniI18n
|
|
144
156
|
end
|
145
157
|
|
146
158
|
def with_interpolation(result, options)
|
147
|
-
if result.
|
159
|
+
if result.is_a?(String) && result.include?('%{')
|
148
160
|
result = Utils.interpolate(result, options)
|
149
161
|
end
|
150
162
|
|
@@ -162,5 +174,13 @@ module MiniI18n
|
|
162
174
|
t(key, options.merge(locale: _locale))
|
163
175
|
end
|
164
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
|
165
185
|
end
|
166
186
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
RSpec.describe "Default Locales Integration" do
|
2
|
+
let(:date) { Date.new(2023, 12, 25) }
|
3
|
+
let(:time) { Time.new(2023, 12, 25, 14, 30) }
|
4
|
+
let(:number) { 1234.56 }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@original_translations = MiniI18n.translations.dup
|
8
|
+
@original_available_locales = MiniI18n.available_locales.dup
|
9
|
+
MiniI18n.available_locales = [:en, :es, :fr, :de, :pt, :it, :nl, :zh, :ja, :ru, :ar]
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
MiniI18n.translations.clear
|
14
|
+
MiniI18n.translations.merge!(@original_translations)
|
15
|
+
MiniI18n.available_locales = @original_available_locales
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Date localization" do
|
19
|
+
it "formats dates according to each locale" do
|
20
|
+
expect(MiniI18n.l(date, locale: :en)).to eq("Monday 25, December, 2023")
|
21
|
+
expect(MiniI18n.l(date, locale: :es)).to eq("25/12/2023")
|
22
|
+
expect(MiniI18n.l(date, locale: :fr)).to eq("lundi 25 décembre 2023")
|
23
|
+
expect(MiniI18n.l(date, locale: :de)).to eq("Montag, 25. Dezember 2023")
|
24
|
+
expect(MiniI18n.l(date, locale: :pt)).to eq("segunda-feira, 25 de dezembro de 2023")
|
25
|
+
expect(MiniI18n.l(date, locale: :it)).to eq("lunedì 25 dicembre 2023")
|
26
|
+
expect(MiniI18n.l(date, locale: :nl)).to eq("maandag 25 december 2023")
|
27
|
+
expect(MiniI18n.l(date, locale: :zh)).to eq("2023年12月25日")
|
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")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "formats short dates according to each locale" do
|
34
|
+
expect(MiniI18n.l(date, format: :short, locale: :en)).to eq("25 Dec 23")
|
35
|
+
expect(MiniI18n.l(date, format: :short, locale: :es)).to eq("25 dic 23")
|
36
|
+
expect(MiniI18n.l(date, format: :short, locale: :fr)).to eq("25 déc 23")
|
37
|
+
expect(MiniI18n.l(date, format: :short, locale: :de)).to eq("25.12.23")
|
38
|
+
expect(MiniI18n.l(date, format: :short, locale: :pt)).to eq("25/12/23")
|
39
|
+
expect(MiniI18n.l(date, format: :short, locale: :it)).to eq("25/12/23")
|
40
|
+
expect(MiniI18n.l(date, format: :short, locale: :nl)).to eq("25-12-23")
|
41
|
+
expect(MiniI18n.l(date, format: :short, locale: :zh)).to eq("12月25日")
|
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")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "Time localization" do
|
49
|
+
it "formats times according to each locale" do
|
50
|
+
expect(MiniI18n.l(time, locale: :en)).to eq("Mon 25, December, 2023 - 14:30")
|
51
|
+
expect(MiniI18n.l(time, locale: :es)).to eq("lun 25 de diciembre de 2023 - 14:30")
|
52
|
+
expect(MiniI18n.l(time, locale: :fr)).to eq("lun 25 décembre 2023 - 14:30")
|
53
|
+
expect(MiniI18n.l(time, locale: :de)).to eq("Mo, 25. Dezember 2023 - 14:30")
|
54
|
+
expect(MiniI18n.l(time, locale: :pt)).to eq("seg, 25 de dezembro de 2023 - 14:30")
|
55
|
+
expect(MiniI18n.l(time, locale: :it)).to eq("lun 25 dicembre 2023 - 14:30")
|
56
|
+
expect(MiniI18n.l(time, locale: :nl)).to eq("ma 25 december 2023 - 14:30")
|
57
|
+
expect(MiniI18n.l(time, locale: :zh)).to eq("2023年12月25日 星期一 14:30")
|
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")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "Number localization" do
|
65
|
+
it "formats numbers according to each locale" do
|
66
|
+
expect(MiniI18n.l(number, locale: :en)).to eq("1,234.56")
|
67
|
+
expect(MiniI18n.l(number, locale: :es)).to eq("1.234,56")
|
68
|
+
expect(MiniI18n.l(number, locale: :fr)).to eq("1 234,56")
|
69
|
+
expect(MiniI18n.l(number, locale: :de)).to eq("1.234,56")
|
70
|
+
expect(MiniI18n.l(number, locale: :pt)).to eq("1.234,56")
|
71
|
+
expect(MiniI18n.l(number, locale: :it)).to eq("1.234,56")
|
72
|
+
expect(MiniI18n.l(number, locale: :nl)).to eq("1.234,56")
|
73
|
+
expect(MiniI18n.l(number, locale: :zh)).to eq("1,234.56")
|
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")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
RSpec.describe 'Global shortcuts' do
|
2
|
+
describe 'T method' do
|
3
|
+
it 'acts as a shortcut for MiniI18n.t' do
|
4
|
+
expect(T(:hello)).to eq 'hello'
|
5
|
+
expect(T(:hello, locale: :fr)).to eq 'bonjour'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'supports all the same options as MiniI18n.t' do
|
9
|
+
expect(T('hello_interpolation', name: 'world')).to eq 'hello world'
|
10
|
+
expect(T('notifications', count: 1)).to eq '1 unread notification'
|
11
|
+
expect(T('non_existent_key', default: 'default')).to eq 'default'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'L method' do
|
16
|
+
it 'acts as a shortcut for MiniI18n.l' do
|
17
|
+
expect(L(1000.25)).to eq '1,000.25'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'supports all the same options as MiniI18n.l' do
|
21
|
+
expect(L(1000, as: :currency)).to eq '1,000 $'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/localization_spec.rb
CHANGED
@@ -42,8 +42,83 @@ RSpec.describe MiniI18n::Localization do
|
|
42
42
|
|
43
43
|
it 'as' do
|
44
44
|
expect(MiniI18n.l(9000, as: :currency)).to eq '9,000 $'
|
45
|
-
expect(MiniI18n.l(9000, as: :currency, locale: :es)).to eq '
|
46
|
-
expect(MiniI18n.l(125.5, as: :distance)).to eq 'Distance
|
45
|
+
expect(MiniI18n.l(9000, as: :currency, locale: :es)).to eq '9.000 €'
|
46
|
+
expect(MiniI18n.l(125.5, as: :distance)).to eq 'Distance -> 125.5 miles'
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
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
|
124
|
+
end
|
data/spec/mini_i18n_spec.rb
CHANGED
@@ -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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,14 +75,27 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- lib/mini_i18n.rb
|
78
|
+
- lib/mini_i18n/kernel_extensions.rb
|
79
|
+
- lib/mini_i18n/locales/ar.yml
|
80
|
+
- lib/mini_i18n/locales/de.yml
|
81
|
+
- lib/mini_i18n/locales/en.yml
|
82
|
+
- lib/mini_i18n/locales/es.yml
|
83
|
+
- lib/mini_i18n/locales/fr.yml
|
84
|
+
- lib/mini_i18n/locales/it.yml
|
85
|
+
- lib/mini_i18n/locales/ja.yml
|
86
|
+
- lib/mini_i18n/locales/nl.yml
|
87
|
+
- lib/mini_i18n/locales/pt.yml
|
88
|
+
- lib/mini_i18n/locales/ru.yml
|
89
|
+
- lib/mini_i18n/locales/zh.yml
|
78
90
|
- lib/mini_i18n/localization.rb
|
79
91
|
- lib/mini_i18n/pluralization.rb
|
80
92
|
- lib/mini_i18n/utils.rb
|
81
93
|
- lib/mini_i18n/version.rb
|
94
|
+
- spec/default_locales_integration_spec.rb
|
82
95
|
- spec/fixtures/locales/en.json
|
83
96
|
- spec/fixtures/locales/en.yml
|
84
|
-
- spec/fixtures/locales/localization.yml
|
85
97
|
- spec/fixtures/locales/multiple.yml
|
98
|
+
- spec/kernel_extensions_spec.rb
|
86
99
|
- spec/localization_spec.rb
|
87
100
|
- spec/mini_i18n_spec.rb
|
88
101
|
- spec/spec_helper.rb
|
@@ -90,7 +103,7 @@ homepage: https://github.com/markets/mini_i18n
|
|
90
103
|
licenses:
|
91
104
|
- MIT
|
92
105
|
metadata: {}
|
93
|
-
post_install_message:
|
106
|
+
post_install_message:
|
94
107
|
rdoc_options: []
|
95
108
|
require_paths:
|
96
109
|
- lib
|
@@ -105,15 +118,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
118
|
- !ruby/object:Gem::Version
|
106
119
|
version: '0'
|
107
120
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
109
|
-
signing_key:
|
121
|
+
rubygems_version: 3.5.16
|
122
|
+
signing_key:
|
110
123
|
specification_version: 4
|
111
124
|
summary: Minimalistic I18n library for Ruby
|
112
125
|
test_files:
|
126
|
+
- spec/default_locales_integration_spec.rb
|
113
127
|
- spec/fixtures/locales/en.json
|
114
128
|
- spec/fixtures/locales/en.yml
|
115
|
-
- spec/fixtures/locales/localization.yml
|
116
129
|
- spec/fixtures/locales/multiple.yml
|
130
|
+
- spec/kernel_extensions_spec.rb
|
117
131
|
- spec/localization_spec.rb
|
118
132
|
- spec/mini_i18n_spec.rb
|
119
133
|
- spec/spec_helper.rb
|