mini_i18n 0.5.0 → 0.6.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.rb +14 -8
- data/lib/mini_i18n/version.rb +1 -1
- data/spec/mini_i18n_spec.rb +10 -0
- data/spec/spec_helper.rb +1 -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: 748e42499af526adff60a56957acc33011de4885
|
4
|
+
data.tar.gz: 33139b385903ab20af789f9bd9ad03bc4a87b519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cf99b8fb0fc6f67230c0a5fdcaa7742b23f1a0323afdeab870a090283ce193e060552a3b5f67d0c68dde7a5ede361a36b5f8f33d6cd267e5d3ae5c7497a2284
|
7
|
+
data.tar.gz: 6a4405281d8ec7086392d650b22a7c714fc906178419b4344850935065ebf07b04e14db7b66aa142df87eba8c3c71e54e24fa093ce7ad23d49d2ae60447cc5c8
|
data/lib/mini_i18n.rb
CHANGED
@@ -8,7 +8,7 @@ module MiniI18n
|
|
8
8
|
include Localization
|
9
9
|
|
10
10
|
DEFAULT_LOCALE = :en
|
11
|
-
|
11
|
+
DEFAULT_SEPARATOR = '.'
|
12
12
|
|
13
13
|
attr_accessor :fallbacks
|
14
14
|
|
@@ -20,12 +20,8 @@ module MiniI18n
|
|
20
20
|
@@default_locale = available_locale?(new_locale) || default_locale
|
21
21
|
end
|
22
22
|
|
23
|
-
def default_available_locales
|
24
|
-
@@default_available_locales ||= translations.keys
|
25
|
-
end
|
26
|
-
|
27
23
|
def available_locales
|
28
|
-
@@available_locales ||=
|
24
|
+
@@available_locales ||= translations.keys
|
29
25
|
end
|
30
26
|
|
31
27
|
def available_locales=(new_locales)
|
@@ -44,6 +40,14 @@ module MiniI18n
|
|
44
40
|
set_locale(new_locale)
|
45
41
|
end
|
46
42
|
|
43
|
+
def separator
|
44
|
+
@@separator ||= DEFAULT_SEPARATOR
|
45
|
+
end
|
46
|
+
|
47
|
+
def separator=(new_separator)
|
48
|
+
@@separator = new_separator || DEFAULT_SEPARATOR
|
49
|
+
end
|
50
|
+
|
47
51
|
def configure
|
48
52
|
yield(self) if block_given?
|
49
53
|
end
|
@@ -63,8 +67,8 @@ module MiniI18n
|
|
63
67
|
scope = options[:scope]
|
64
68
|
|
65
69
|
keys = [_locale.to_s]
|
66
|
-
keys << scope.to_s.split(
|
67
|
-
keys << key.to_s.split(
|
70
|
+
keys << scope.to_s.split(separator) if scope
|
71
|
+
keys << key.to_s.split(separator)
|
68
72
|
keys = keys.flatten
|
69
73
|
|
70
74
|
result = lookup(*keys)
|
@@ -81,9 +85,11 @@ module MiniI18n
|
|
81
85
|
|
82
86
|
def set_locale(new_locale)
|
83
87
|
new_locale = new_locale.to_s
|
88
|
+
|
84
89
|
if available_locale?(new_locale)
|
85
90
|
Thread.current[:mini_i18n_locale] = new_locale
|
86
91
|
end
|
92
|
+
|
87
93
|
locale
|
88
94
|
end
|
89
95
|
|
data/lib/mini_i18n/version.rb
CHANGED
data/spec/mini_i18n_spec.rb
CHANGED
@@ -37,6 +37,16 @@ RSpec.describe MiniI18n do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
describe 'separator' do
|
41
|
+
it 'allows to customize separator for nested keys' do
|
42
|
+
MiniI18n.separator = ' '
|
43
|
+
expect(MiniI18n.t('second_level hello')).to eq 'hello 2'
|
44
|
+
|
45
|
+
MiniI18n.separator = '::'
|
46
|
+
expect(MiniI18n.t('second_level::hello')).to eq 'hello 2'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
40
50
|
describe 'translate' do
|
41
51
|
it "simple key" do
|
42
52
|
expect(MiniI18n.t(:hello)).to eq 'hello'
|
data/spec/spec_helper.rb
CHANGED
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.6.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-
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|