r18n-core 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/ChangeLog.md +6 -1
- data/README.md +1 -20
- data/Rakefile +5 -3
- data/lib/r18n-core.rb +55 -55
- data/lib/r18n-core/filter_list.rb +34 -36
- data/lib/r18n-core/filters.rb +68 -51
- data/lib/r18n-core/helpers.rb +17 -17
- data/lib/r18n-core/i18n.rb +46 -39
- data/lib/r18n-core/locale.rb +79 -70
- data/lib/r18n-core/translated.rb +65 -66
- data/lib/r18n-core/translated_string.rb +24 -24
- data/lib/r18n-core/translation.rb +31 -30
- data/lib/r18n-core/unsupported_locale.rb +22 -24
- data/lib/r18n-core/untranslated.rb +35 -33
- data/lib/r18n-core/utils.rb +26 -25
- data/lib/r18n-core/version.rb +4 -1
- data/lib/r18n-core/yaml_loader.rb +26 -25
- data/lib/r18n-core/yaml_methods.rb +25 -28
- data/locales/af.rb +15 -8
- data/locales/az.rb +19 -12
- data/locales/bg.rb +16 -9
- data/locales/ca.rb +16 -9
- data/locales/cs.rb +27 -20
- data/locales/da.rb +15 -8
- data/locales/de.rb +16 -9
- data/locales/en-au.rb +10 -5
- data/locales/en-gb.rb +12 -5
- data/locales/en-us.rb +12 -5
- data/locales/en.rb +29 -22
- data/locales/eo.rb +14 -7
- data/locales/es-us.rb +12 -5
- data/locales/es.rb +14 -7
- data/locales/fa.rb +48 -32
- data/locales/fi.rb +19 -12
- data/locales/fr.rb +22 -15
- data/locales/gl.rb +15 -8
- data/locales/hr.rb +24 -17
- data/locales/hu.rb +28 -21
- data/locales/id.rb +14 -7
- data/locales/it.rb +21 -14
- data/locales/ja.rb +15 -8
- data/locales/kk.rb +17 -10
- data/locales/ko.rb +15 -9
- data/locales/lv.rb +24 -17
- data/locales/mn.rb +10 -3
- data/locales/nb.rb +15 -8
- data/locales/nl.rb +15 -8
- data/locales/no.rb +11 -16
- data/locales/pl.rb +26 -19
- data/locales/pt-br.rb +12 -5
- data/locales/pt.rb +17 -10
- data/locales/ru.rb +26 -19
- data/locales/sk.rb +27 -20
- data/locales/sr-latn.rb +27 -22
- data/locales/sv-se.rb +15 -8
- data/locales/th.rb +27 -20
- data/locales/tr.rb +16 -9
- data/locales/uk.rb +19 -12
- data/locales/vi.rb +14 -7
- data/locales/zh-cn.rb +12 -5
- data/locales/zh-tw.rb +15 -8
- data/locales/zh.rb +14 -7
- data/r18n-core.gemspec +5 -3
- data/spec/filters_spec.rb +71 -67
- data/spec/i18n_spec.rb +73 -51
- data/spec/locale_spec.rb +73 -68
- data/spec/locales/cs_spec.rb +2 -2
- data/spec/locales/en-us_spec.rb +9 -9
- data/spec/locales/en_spec.rb +2 -2
- data/spec/locales/fa_spec.rb +3 -3
- data/spec/locales/fr_spec.rb +2 -2
- data/spec/locales/hu_spec.rb +7 -7
- data/spec/locales/it_spec.rb +3 -3
- data/spec/locales/no_spec.rb +9 -0
- data/spec/locales/pl_spec.rb +2 -2
- data/spec/locales/ru_spec.rb +2 -2
- data/spec/locales/sk_spec.rb +2 -2
- data/spec/locales/th_spec.rb +2 -2
- data/spec/locales/vi_spec.rb +2 -2
- data/spec/r18n_spec.rb +44 -38
- data/spec/spec_helper.rb +13 -9
- data/spec/translated_spec.rb +48 -31
- data/spec/translation_spec.rb +29 -27
- data/spec/translations/general/en.yml +0 -2
- data/spec/yaml_loader_spec.rb +22 -18
- metadata +5 -3
data/spec/translation_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Translation do
|
4
|
-
|
5
4
|
it "returns unstranslated string if translation isn't found" do
|
6
5
|
i18n = R18n::I18n.new('en', DIR)
|
7
6
|
expect(i18n.not.exists).to be_kind_of(R18n::Untranslated)
|
@@ -18,7 +17,7 @@ describe R18n::Translation do
|
|
18
17
|
expect(i18n.one | 'default').to eq('One')
|
19
18
|
end
|
20
19
|
|
21
|
-
it
|
20
|
+
it 'returns strings which can be used as normal strings' do
|
22
21
|
i18n = R18n::I18n.new('en', DIR)
|
23
22
|
expect(i18n.not.exists).not_to be_translated
|
24
23
|
expect(i18n.not.exists.to_s).to be_kind_of(String)
|
@@ -33,7 +32,7 @@ describe R18n::Translation do
|
|
33
32
|
expect(i18n.one.split.first.to_s).to be_kind_of(String)
|
34
33
|
end
|
35
34
|
|
36
|
-
it
|
35
|
+
it 'returns strings compatible with activesupport json encoding' do
|
37
36
|
require 'active_support'
|
38
37
|
|
39
38
|
i18n = R18n::I18n.new('en', DIR)
|
@@ -42,14 +41,14 @@ describe R18n::Translation do
|
|
42
41
|
expect(json).to eq('{"one":"One"}')
|
43
42
|
end
|
44
43
|
|
45
|
-
it
|
44
|
+
it 'returns strings by Boolean keys (true, false)' do
|
46
45
|
i18n = R18n::I18n.new('en', DIR)
|
47
46
|
|
48
47
|
expect(i18n.boolean[true]).to eq('Boolean is true')
|
49
48
|
expect(i18n.boolean[false]).to eq('Boolean is false')
|
50
49
|
end
|
51
50
|
|
52
|
-
it
|
51
|
+
it 'returns html escaped string if html_safe is defined' do
|
53
52
|
klass = Class.new(R18n::TranslatedString) do
|
54
53
|
def html_safe
|
55
54
|
'2'
|
@@ -61,7 +60,7 @@ describe R18n::Translation do
|
|
61
60
|
expect(str.html_safe).to eq('2')
|
62
61
|
end
|
63
62
|
|
64
|
-
it
|
63
|
+
it 'returns unescaped string if html_safe is not defined' do
|
65
64
|
klass = Class.new(R18n::TranslatedString) do
|
66
65
|
undef_method :html_safe if method_defined?(:html_safe)
|
67
66
|
end
|
@@ -71,15 +70,15 @@ describe R18n::Translation do
|
|
71
70
|
expect(str.to_s).to eq('a & b')
|
72
71
|
end
|
73
72
|
|
74
|
-
it
|
75
|
-
i18n = R18n::I18n.new([
|
73
|
+
it 'loads use hierarchical translations' do
|
74
|
+
i18n = R18n::I18n.new(%w[ru en], DIR)
|
76
75
|
expect(i18n.in.another.level).to eq('Иерархический')
|
77
76
|
expect(i18n[:in][:another][:level]).to eq('Иерархический')
|
78
77
|
expect(i18n['in']['another']['level']).to eq('Иерархический')
|
79
78
|
expect(i18n.only.english).to eq('Only in English')
|
80
79
|
end
|
81
80
|
|
82
|
-
it
|
81
|
+
it 'saves path for translation' do
|
83
82
|
i18n = R18n::I18n.new('en', DIR)
|
84
83
|
|
85
84
|
expect(i18n.in.another.level.path).to eq('in.another.level')
|
@@ -92,52 +91,55 @@ describe R18n::Translation do
|
|
92
91
|
expect(i18n.not.translated_path).to eq('')
|
93
92
|
end
|
94
93
|
|
95
|
-
it
|
94
|
+
it 'returns translation keys' do
|
96
95
|
i18n = R18n::I18n.new('en', [DIR, TWO])
|
97
|
-
expect(i18n.in.translation_keys).to match_array([
|
96
|
+
expect(i18n.in.translation_keys).to match_array(%w[another two])
|
98
97
|
end
|
99
98
|
|
100
|
-
it
|
101
|
-
i18n = R18n::I18n.new([
|
99
|
+
it 'returns string with locale info' do
|
100
|
+
i18n = R18n::I18n.new(%w[nolocale en], DIR)
|
102
101
|
expect(i18n.one.locale).to eq(R18n::UnsupportedLocale.new('nolocale'))
|
103
102
|
expect(i18n.two.locale).to eq(R18n.locale('en'))
|
104
103
|
end
|
105
104
|
|
106
|
-
it
|
105
|
+
it 'filters typed data' do
|
107
106
|
en = R18n.locale('en')
|
108
107
|
translation = R18n::Translation.new(en, '', locale: en, translations:
|
109
|
-
{ 'count' => R18n::Typed.new('pl',
|
108
|
+
{ 'count' => R18n::Typed.new('pl', 1 => 'one', 'n' => 'many') })
|
110
109
|
|
111
110
|
expect(translation.count(1)).to eq('one')
|
112
111
|
expect(translation.count(5)).to eq('many')
|
113
112
|
end
|
114
113
|
|
115
|
-
it
|
114
|
+
it 'returns hash of translations' do
|
116
115
|
i18n = R18n::I18n.new('en', DIR)
|
117
|
-
expect(i18n.in.to_hash).to eq(
|
116
|
+
expect(i18n.in.to_hash).to eq(
|
118
117
|
'another' => { 'level' => 'Hierarchical' }
|
119
|
-
|
118
|
+
)
|
120
119
|
end
|
121
120
|
|
122
|
-
it
|
121
|
+
it 'returns untranslated, when we go deeper string' do
|
123
122
|
en = R18n.locale('en')
|
124
|
-
translation = R18n::Translation.new(
|
125
|
-
locale: en, translations: { 'a' => 'A' }
|
123
|
+
translation = R18n::Translation.new(
|
124
|
+
en, '', locale: en, translations: { 'a' => 'A' }
|
125
|
+
)
|
126
126
|
|
127
127
|
expect(translation.a.no_tr).to be_kind_of(R18n::Untranslated)
|
128
128
|
expect(translation.a.no_tr.translated_path).to eq('a.')
|
129
129
|
expect(translation.a.no_tr.untranslated_path).to eq('no_tr')
|
130
130
|
end
|
131
131
|
|
132
|
-
it
|
132
|
+
it 'inspects translation' do
|
133
133
|
en = R18n.locale('en')
|
134
134
|
|
135
|
-
translation = R18n::Translation.new(
|
136
|
-
locale: en, translations: { 'a' => 'A' }
|
135
|
+
translation = R18n::Translation.new(
|
136
|
+
en, 'a', locale: en, translations: { 'a' => 'A' }
|
137
|
+
)
|
137
138
|
expect(translation.inspect).to eq('Translation `a` for en {"a"=>"A"}')
|
138
139
|
|
139
|
-
translation = R18n::Translation.new(
|
140
|
-
locale: en, translations: { 'a' => 'A' }
|
140
|
+
translation = R18n::Translation.new(
|
141
|
+
en, '', locale: en, translations: { 'a' => 'A' }
|
142
|
+
)
|
141
143
|
expect(translation.inspect).to eq('Translation root for en {"a"=>"A"}')
|
142
144
|
|
143
145
|
translation = R18n::Translation.new(en, '')
|
data/spec/yaml_loader_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe R18n::Loader::YAML do
|
4
4
|
before :all do
|
@@ -13,40 +13,44 @@ describe R18n::Loader::YAML do
|
|
13
13
|
@loader = R18n::Loader::YAML.new(DIR)
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
expect(@loader.dir).to eq(DIR
|
16
|
+
it 'returns dir with translations' do
|
17
|
+
expect(@loader.dir).to eq(DIR)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'equals to another YAML loader with same dir' do
|
21
21
|
expect(@loader).to eq(R18n::Loader::YAML.new(DIR))
|
22
22
|
expect(@loader).not_to eq(Class.new(R18n::Loader::YAML).new(DIR))
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
expect(@loader.available).to match_array([
|
27
|
-
|
28
|
-
|
25
|
+
it 'returns all available translations' do
|
26
|
+
expect(@loader.available).to match_array([
|
27
|
+
R18n.locale('ru'),
|
28
|
+
R18n.locale('en'),
|
29
|
+
R18n.locale('nolocale')
|
30
|
+
])
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
32
|
-
expect(@loader.load(R18n.locale('ru'))).to eq(
|
33
|
+
it 'loads translation' do
|
34
|
+
expect(@loader.load(R18n.locale('ru'))).to eq(
|
33
35
|
'one' => 'Один',
|
34
36
|
'in' => { 'another' => { 'level' => 'Иерархический' } },
|
35
37
|
'typed' => R18n::Typed.new('my', 'value')
|
36
|
-
|
38
|
+
)
|
37
39
|
end
|
38
40
|
|
39
|
-
it
|
41
|
+
it 'returns hash by dir' do
|
40
42
|
expect(@loader.hash).to eq(R18n::Loader::YAML.new(DIR).hash)
|
41
43
|
end
|
42
44
|
|
43
|
-
it
|
45
|
+
it 'loads in dir recursively' do
|
44
46
|
loader = R18n::Loader::YAML.new(TRANSLATIONS)
|
45
|
-
expect(loader.available).to match_array([
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
expect(loader.available).to match_array([
|
48
|
+
R18n.locale('ru'),
|
49
|
+
R18n.locale('en'),
|
50
|
+
R18n.locale('fr'),
|
51
|
+
R18n.locale('notransl'),
|
52
|
+
R18n.locale('nolocale')
|
53
|
+
])
|
50
54
|
|
51
55
|
translation = loader.load(R18n.locale('en'))
|
52
56
|
expect(translation['two']).to eq('Two')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
R18n is a i18n tool to translate your Ruby application.
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- spec/locales/fr_spec.rb
|
136
136
|
- spec/locales/hu_spec.rb
|
137
137
|
- spec/locales/it_spec.rb
|
138
|
+
- spec/locales/no_spec.rb
|
138
139
|
- spec/locales/pl_spec.rb
|
139
140
|
- spec/locales/ru_spec.rb
|
140
141
|
- spec/locales/sk_spec.rb
|
@@ -173,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
174
|
version: '0'
|
174
175
|
requirements: []
|
175
176
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.7.6
|
177
178
|
signing_key:
|
178
179
|
specification_version: 4
|
179
180
|
summary: I18n tool to translate your Ruby application.
|
@@ -188,6 +189,7 @@ test_files:
|
|
188
189
|
- spec/locales/fr_spec.rb
|
189
190
|
- spec/locales/hu_spec.rb
|
190
191
|
- spec/locales/it_spec.rb
|
192
|
+
- spec/locales/no_spec.rb
|
191
193
|
- spec/locales/pl_spec.rb
|
192
194
|
- spec/locales/ru_spec.rb
|
193
195
|
- spec/locales/sk_spec.rb
|