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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1535503921791b7c7660516aab9b224eda60883
4
- data.tar.gz: 87d9b5f991ba9dca7da8310b2fc76d43b82a9100
3
+ metadata.gz: 748e42499af526adff60a56957acc33011de4885
4
+ data.tar.gz: 33139b385903ab20af789f9bd9ad03bc4a87b519
5
5
  SHA512:
6
- metadata.gz: 58ba16e72dc2d6e2211999a89948490721f4ee23d7fc9781f913395bb2a44e80a21605ad0b8f7cb0c8be92d528ecf1fe0f46318a93935bfe23d67438904f2a3f
7
- data.tar.gz: adf6f4cedaf7fc8b7c58179eb4e57a3b98a85cdc4269111b69411fcac45a0a9844d81cc4273ffff95e0b801cc035b9a6ea98fcb1e0a5c7862290636000b5d692
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
- SEPARATOR = '.'
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 ||= default_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(SEPARATOR) if scope
67
- keys << key.to_s.split(SEPARATOR)
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
 
@@ -1,3 +1,3 @@
1
1
  module MiniI18n
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -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
@@ -10,6 +10,7 @@ RSpec.configure do |config|
10
10
 
11
11
  config.before(:each) do
12
12
  MiniI18n.locale = :en
13
+ MiniI18n.separator = '.'
13
14
  MiniI18n.fallbacks = false
14
15
  MiniI18n.available_locales = [:en, :es, :fr]
15
16
  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.5.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-08-30 00:00:00.000000000 Z
11
+ date: 2018-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler