mini_i18n 0.9.0 → 1.0.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/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/zh.yml +17 -0
- data/lib/mini_i18n/localization.rb +1 -1
- data/lib/mini_i18n/version.rb +1 -1
- data/lib/mini_i18n.rb +11 -0
- data/spec/default_locales_integration_spec.rb +71 -0
- data/spec/fixtures/locales/en.yml +5 -1
- data/spec/kernel_extensions_spec.rb +24 -0
- data/spec/localization_spec.rb +3 -3
- metadata +20 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cb5cf9833c1d4bfb7f45fed780cd5207ae00b1b51d9f2f5c53bd3239675920b
|
4
|
+
data.tar.gz: 8bc35757a1d45205133ffd112c1681698629d01faac6e846805c9f970673e57f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0e50f36c05e3857048ea02754c0c5794d2bae63d3524153adbcaeea16b00c080784317051994930fd4a19ca7bd42e5a4d24fbf21ec2b7227f73a6b872817c71
|
7
|
+
data.tar.gz: 567b252d2c586e3b7678f3f7ce19e89195cf665a685141eba42bd259a6a09c26c353717f8f2fc232225547aa3f43ef495606cd3fa780aef96400cebaf5fe865b
|
@@ -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
|
+
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: '.'
|
@@ -27,7 +27,7 @@ module MiniI18n
|
|
27
27
|
locale = options[:locale]
|
28
28
|
delimiter = MiniI18n.t("number.format.delimiter", locale: locale)
|
29
29
|
separator = MiniI18n.t("number.format.separator", locale: locale)
|
30
|
-
integer, fractional = number.to_s.split(
|
30
|
+
integer, fractional = number.to_s.split('.')
|
31
31
|
|
32
32
|
integer.to_s.gsub!(DELIMITER_REGEX) do |match|
|
33
33
|
"#{match}#{delimiter}"
|
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
|
@@ -0,0 +1,71 @@
|
|
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]
|
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
|
+
end
|
30
|
+
|
31
|
+
it "formats short dates according to each locale" do
|
32
|
+
expect(MiniI18n.l(date, format: :short, locale: :en)).to eq("25 Dec 23")
|
33
|
+
expect(MiniI18n.l(date, format: :short, locale: :es)).to eq("25 dic 23")
|
34
|
+
expect(MiniI18n.l(date, format: :short, locale: :fr)).to eq("25 déc 23")
|
35
|
+
expect(MiniI18n.l(date, format: :short, locale: :de)).to eq("25.12.23")
|
36
|
+
expect(MiniI18n.l(date, format: :short, locale: :pt)).to eq("25/12/23")
|
37
|
+
expect(MiniI18n.l(date, format: :short, locale: :it)).to eq("25/12/23")
|
38
|
+
expect(MiniI18n.l(date, format: :short, locale: :nl)).to eq("25-12-23")
|
39
|
+
expect(MiniI18n.l(date, format: :short, locale: :zh)).to eq("12月25日")
|
40
|
+
expect(MiniI18n.l(date, format: :short, locale: :ja)).to eq("12/25")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "Time localization" do
|
45
|
+
it "formats times according to each locale" do
|
46
|
+
expect(MiniI18n.l(time, locale: :en)).to eq("Mon 25, December, 2023 - 14:30")
|
47
|
+
expect(MiniI18n.l(time, locale: :es)).to eq("lun 25 de diciembre de 2023 - 14:30")
|
48
|
+
expect(MiniI18n.l(time, locale: :fr)).to eq("lun 25 décembre 2023 - 14:30")
|
49
|
+
expect(MiniI18n.l(time, locale: :de)).to eq("Mo, 25. Dezember 2023 - 14:30")
|
50
|
+
expect(MiniI18n.l(time, locale: :pt)).to eq("seg, 25 de dezembro de 2023 - 14:30")
|
51
|
+
expect(MiniI18n.l(time, locale: :it)).to eq("lun 25 dicembre 2023 - 14:30")
|
52
|
+
expect(MiniI18n.l(time, locale: :nl)).to eq("ma 25 december 2023 - 14:30")
|
53
|
+
expect(MiniI18n.l(time, locale: :zh)).to eq("2023年12月25日 星期一 14:30")
|
54
|
+
expect(MiniI18n.l(time, locale: :ja)).to eq("2023年12月25日(月) 14時30分")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "Number localization" do
|
59
|
+
it "formats numbers according to each locale" do
|
60
|
+
expect(MiniI18n.l(number, locale: :en)).to eq("1,234.56")
|
61
|
+
expect(MiniI18n.l(number, locale: :es)).to eq("1.234,56")
|
62
|
+
expect(MiniI18n.l(number, locale: :fr)).to eq("1 234,56")
|
63
|
+
expect(MiniI18n.l(number, locale: :de)).to eq("1.234,56")
|
64
|
+
expect(MiniI18n.l(number, locale: :pt)).to eq("1.234,56")
|
65
|
+
expect(MiniI18n.l(number, locale: :it)).to eq("1.234,56")
|
66
|
+
expect(MiniI18n.l(number, locale: :nl)).to eq("1.234,56")
|
67
|
+
expect(MiniI18n.l(number, locale: :zh)).to eq("1,234.56")
|
68
|
+
expect(MiniI18n.l(number, locale: :ja)).to eq("1,234.56")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
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,8 @@ 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
|
-
end
|
49
|
+
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: 0.
|
4
|
+
version: 1.0.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-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,14 +75,25 @@ 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/de.yml
|
80
|
+
- lib/mini_i18n/locales/en.yml
|
81
|
+
- lib/mini_i18n/locales/es.yml
|
82
|
+
- lib/mini_i18n/locales/fr.yml
|
83
|
+
- lib/mini_i18n/locales/it.yml
|
84
|
+
- lib/mini_i18n/locales/ja.yml
|
85
|
+
- lib/mini_i18n/locales/nl.yml
|
86
|
+
- lib/mini_i18n/locales/pt.yml
|
87
|
+
- lib/mini_i18n/locales/zh.yml
|
78
88
|
- lib/mini_i18n/localization.rb
|
79
89
|
- lib/mini_i18n/pluralization.rb
|
80
90
|
- lib/mini_i18n/utils.rb
|
81
91
|
- lib/mini_i18n/version.rb
|
92
|
+
- spec/default_locales_integration_spec.rb
|
82
93
|
- spec/fixtures/locales/en.json
|
83
94
|
- spec/fixtures/locales/en.yml
|
84
|
-
- spec/fixtures/locales/localization.yml
|
85
95
|
- spec/fixtures/locales/multiple.yml
|
96
|
+
- spec/kernel_extensions_spec.rb
|
86
97
|
- spec/localization_spec.rb
|
87
98
|
- spec/mini_i18n_spec.rb
|
88
99
|
- spec/spec_helper.rb
|
@@ -90,7 +101,7 @@ homepage: https://github.com/markets/mini_i18n
|
|
90
101
|
licenses:
|
91
102
|
- MIT
|
92
103
|
metadata: {}
|
93
|
-
post_install_message:
|
104
|
+
post_install_message:
|
94
105
|
rdoc_options: []
|
95
106
|
require_paths:
|
96
107
|
- lib
|
@@ -105,15 +116,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
116
|
- !ruby/object:Gem::Version
|
106
117
|
version: '0'
|
107
118
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
109
|
-
signing_key:
|
119
|
+
rubygems_version: 3.5.16
|
120
|
+
signing_key:
|
110
121
|
specification_version: 4
|
111
122
|
summary: Minimalistic I18n library for Ruby
|
112
123
|
test_files:
|
124
|
+
- spec/default_locales_integration_spec.rb
|
113
125
|
- spec/fixtures/locales/en.json
|
114
126
|
- spec/fixtures/locales/en.yml
|
115
|
-
- spec/fixtures/locales/localization.yml
|
116
127
|
- spec/fixtures/locales/multiple.yml
|
128
|
+
- spec/kernel_extensions_spec.rb
|
117
129
|
- spec/localization_spec.rb
|
118
130
|
- spec/mini_i18n_spec.rb
|
119
131
|
- spec/spec_helper.rb
|