mini_i18n 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mini_i18n/version.rb +1 -1
- data/lib/mini_i18n.rb +18 -2
- data/spec/fixtures/locales/en.yml +5 -1
- data/spec/mini_i18n_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cba824b157c9dde80eaaaf9be9f5515d94e971e9
|
4
|
+
data.tar.gz: 5fbd8419e4aafde608285e00f202c15b15756a32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 398e2a9136851a66f7436909d14977aa6983c6ea6f4fbcf554c39bffdd918cb544fdfb09a26557e97e5cf0001935618375b3f6d4a7c9d561ca8f78c77b406e17
|
7
|
+
data.tar.gz: 4e1ff97230966d61692d0f5ab334cb125914664f73c391eb554f909d8a34da22d30ea3b753d1bcc04f64190157b62ef9cb5fa0abdb5221eb6596f01b7d8bea57
|
data/lib/mini_i18n/version.rb
CHANGED
data/lib/mini_i18n.rb
CHANGED
@@ -65,17 +65,29 @@ module MiniI18n
|
|
65
65
|
|
66
66
|
_locale = available_locale?(options[:locale]) || locale
|
67
67
|
scope = options[:scope]
|
68
|
+
count = options[:count]
|
68
69
|
|
69
70
|
keys = [_locale.to_s]
|
70
71
|
keys << scope.to_s.split(SEPARATOR) if scope
|
71
72
|
keys << key.to_s.split(SEPARATOR)
|
72
73
|
keys = keys.flatten
|
73
74
|
|
74
|
-
result =
|
75
|
+
result = lookup(*keys)
|
75
76
|
|
76
77
|
if fallbacks && result.empty?
|
77
78
|
keys = Utils.replace_with(keys, _locale, default_locale.to_s)
|
78
|
-
result =
|
79
|
+
result = lookup(*keys)
|
80
|
+
end
|
81
|
+
|
82
|
+
if count && result.is_a?(Hash)
|
83
|
+
case count
|
84
|
+
when 0
|
85
|
+
result = result["zero"]
|
86
|
+
when 1
|
87
|
+
result = result["one"]
|
88
|
+
else
|
89
|
+
result = result["many"]
|
90
|
+
end
|
79
91
|
end
|
80
92
|
|
81
93
|
if result.respond_to?(:match) && result.match(/%{\w+}/)
|
@@ -100,5 +112,9 @@ module MiniI18n
|
|
100
112
|
new_locale = new_locale.to_s
|
101
113
|
available_locales.include?(new_locale) && new_locale
|
102
114
|
end
|
115
|
+
|
116
|
+
def lookup(*keys)
|
117
|
+
translations.dig(*keys)
|
118
|
+
end
|
103
119
|
end
|
104
120
|
end
|
data/spec/mini_i18n_spec.rb
CHANGED
@@ -85,5 +85,11 @@ RSpec.describe MiniI18n do
|
|
85
85
|
MiniI18n.fallbacks = true
|
86
86
|
expect(MiniI18n.t('fallback', locale: :es)).to eq 'fallback'
|
87
87
|
end
|
88
|
+
|
89
|
+
it "pluralization" do
|
90
|
+
expect(MiniI18n.t('notifications', count: 0)).to eq 'no unread notifications'
|
91
|
+
expect(MiniI18n.t('notifications', count: 1)).to eq '1 unread notification'
|
92
|
+
expect(MiniI18n.t('notifications', count: 2)).to eq '2 unread notifications'
|
93
|
+
end
|
88
94
|
end
|
89
95
|
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: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|