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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32665206618cf4c4a45344aae4696c61f4a66b36
4
- data.tar.gz: cf097c2379dcc4df553f3de6268484a02e9d76f5
3
+ metadata.gz: cba824b157c9dde80eaaaf9be9f5515d94e971e9
4
+ data.tar.gz: 5fbd8419e4aafde608285e00f202c15b15756a32
5
5
  SHA512:
6
- metadata.gz: aa093915daa4b2db6191e00e8e85c1a45842e3642df4299ea3509e27e758cc6d91c68664ddf2357197b10df82fd07efaa4e3467661d31169e4d7ba7b95e142a2
7
- data.tar.gz: 920f5bff55a01206f365c5a1bc2286b0bc8c639b2d1500883ea95b2da6cad9308eadd847fdc231c26ed3146ec7c73d3f702fad51ec860a9785757b9471879d45
6
+ metadata.gz: 398e2a9136851a66f7436909d14977aa6983c6ea6f4fbcf554c39bffdd918cb544fdfb09a26557e97e5cf0001935618375b3f6d4a7c9d561ca8f78c77b406e17
7
+ data.tar.gz: 4e1ff97230966d61692d0f5ab334cb125914664f73c391eb554f909d8a34da22d30ea3b753d1bcc04f64190157b62ef9cb5fa0abdb5221eb6596f01b7d8bea57
@@ -1,3 +1,3 @@
1
1
  module MiniI18n
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
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 = translations.dig(*keys)
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 = translations.dig(*keys)
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
@@ -3,4 +3,8 @@ en:
3
3
  hello_interpolation: "hello %{name}"
4
4
  fallback: "fallback"
5
5
  second_level:
6
- hello: ""
6
+ hello: ""
7
+ notifications:
8
+ zero: 'no unread notifications'
9
+ one: '1 unread notification'
10
+ many: '%{count} unread notifications'
@@ -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.3.1
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-24 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler