r18n-core 4.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +398 -0
  3. data/README.md +23 -13
  4. data/lib/r18n-core.rb +10 -25
  5. data/lib/r18n-core/filter_list.rb +6 -3
  6. data/lib/r18n-core/filters.rb +21 -22
  7. data/lib/r18n-core/i18n.rb +9 -16
  8. data/lib/r18n-core/locale.rb +20 -21
  9. data/lib/r18n-core/locales/cy.rb +1 -1
  10. data/lib/r18n-core/locales/en-au.rb +1 -1
  11. data/lib/r18n-core/locales/en-gb.rb +1 -1
  12. data/lib/r18n-core/locales/en-us.rb +1 -1
  13. data/lib/r18n-core/locales/en.rb +2 -2
  14. data/lib/r18n-core/locales/es-cl.rb +1 -1
  15. data/lib/r18n-core/locales/es-us.rb +1 -1
  16. data/lib/r18n-core/locales/es.rb +2 -0
  17. data/lib/r18n-core/locales/fi.rb +2 -2
  18. data/lib/r18n-core/locales/fr.rb +3 -3
  19. data/lib/r18n-core/locales/it.rb +3 -3
  20. data/lib/r18n-core/locales/pt.rb +2 -0
  21. data/lib/r18n-core/locales/zh-cn.rb +1 -1
  22. data/lib/r18n-core/locales/zh-tw.rb +1 -1
  23. data/lib/r18n-core/locales/zh.rb +2 -0
  24. data/lib/r18n-core/translated.rb +4 -4
  25. data/lib/r18n-core/translated_string.rb +1 -6
  26. data/lib/r18n-core/translation.rb +1 -1
  27. data/lib/r18n-core/unsupported_locale.rb +2 -0
  28. data/lib/r18n-core/utils.rb +1 -1
  29. data/lib/r18n-core/version.rb +1 -1
  30. metadata +198 -89
  31. data/.rspec +0 -1
  32. data/Rakefile +0 -13
  33. data/r18n-core.gemspec +0 -29
  34. data/spec/filters_spec.rb +0 -327
  35. data/spec/i18n_spec.rb +0 -274
  36. data/spec/locale_spec.rb +0 -251
  37. data/spec/locales/af_spec.rb +0 -9
  38. data/spec/locales/cs_spec.rb +0 -23
  39. data/spec/locales/en-us_spec.rb +0 -28
  40. data/spec/locales/en_spec.rb +0 -13
  41. data/spec/locales/es-us_spec.rb +0 -11
  42. data/spec/locales/fa_spec.rb +0 -10
  43. data/spec/locales/fi_spec.rb +0 -9
  44. data/spec/locales/fr_spec.rb +0 -9
  45. data/spec/locales/hu_spec.rb +0 -19
  46. data/spec/locales/id_spec.rb +0 -23
  47. data/spec/locales/it_spec.rb +0 -10
  48. data/spec/locales/no_spec.rb +0 -9
  49. data/spec/locales/pl_spec.rb +0 -23
  50. data/spec/locales/ru_spec.rb +0 -23
  51. data/spec/locales/sk_spec.rb +0 -23
  52. data/spec/locales/th_spec.rb +0 -9
  53. data/spec/locales/vi_spec.rb +0 -9
  54. data/spec/r18n_spec.rb +0 -192
  55. data/spec/spec_helper.rb +0 -38
  56. data/spec/translated_spec.rb +0 -225
  57. data/spec/translation_spec.rb +0 -189
  58. data/spec/translations/extension/deep/en.yml +0 -1
  59. data/spec/translations/extension/en.yml +0 -2
  60. data/spec/translations/extension/notransl.yml +0 -1
  61. data/spec/translations/general/en.yml +0 -52
  62. data/spec/translations/general/nolocale.yml +0 -6
  63. data/spec/translations/general/ru.yml +0 -7
  64. data/spec/translations/two/en.yml +0 -2
  65. data/spec/translations/two/fr.yml +0 -0
  66. data/spec/translations/with_regions/en-US.yml +0 -0
  67. data/spec/translations/yaml/en-GB.yml +0 -1
  68. data/spec/translations/yaml/en-us.yml +0 -1
  69. data/spec/translations/yaml/en.yaml +0 -1
  70. data/spec/yaml_loader_spec.rb +0 -63
@@ -1,189 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Translation do
4
- it "returns unstranslated string if translation isn't found" do
5
- i18n = R18n::I18n.new('en', DIR)
6
- expect(i18n.not.exists).to be_kind_of(R18n::Untranslated)
7
- expect(i18n.not.exists).not_to be_translated
8
- expect(i18n.not.exists | 'default').to eq('default')
9
- expect(i18n.not.exists.locale).to eq(R18n.locale('en'))
10
-
11
- expect(i18n.not.exists).to eq(i18n.not.exists)
12
- expect(i18n.not.exists).not_to eq(i18n.not.exists2)
13
-
14
- expect(i18n.in | 'default').to eq('default')
15
-
16
- expect(i18n.one).to be_translated
17
- expect(i18n.one | 'default').to eq('One')
18
- end
19
-
20
- it 'returns strings which can be used as normal strings' do
21
- i18n = R18n::I18n.new('en', DIR)
22
- expect(i18n.not.exists).not_to be_translated
23
- expect(i18n.not.exists.to_s).to be_kind_of(String)
24
- expect(i18n.not.exists.to_s.split.first).to be_kind_of(String)
25
- expect(i18n.not.exists.to_s.split.first.to_s).to be_kind_of(String)
26
-
27
- expect(i18n.one).to be_translated
28
- expect(i18n.one.to_s).to be_kind_of(String)
29
- expect(i18n.one.to_s.split.first).to be_kind_of(String)
30
- expect(i18n.one.to_s.split.first.to_s).to be_kind_of(String)
31
- expect(i18n.one.split.first).to be_kind_of(String)
32
- expect(i18n.one.split.first.to_s).to be_kind_of(String)
33
- end
34
-
35
- it 'returns strings compatible with activesupport json encoding' do
36
- require 'active_support'
37
-
38
- i18n = R18n::I18n.new('en', DIR)
39
- json = ActiveSupport::JSON.encode(one: i18n.one)
40
-
41
- expect(json).to eq('{"one":"One"}')
42
- end
43
-
44
- it 'returns strings by Boolean keys (true, false)' do
45
- i18n = R18n::I18n.new('en', DIR)
46
-
47
- expect(i18n.boolean[true]).to eq('Boolean is true')
48
- expect(i18n.boolean[false]).to eq('Boolean is false')
49
- end
50
-
51
- it 'returns html escaped string if html_safe is defined' do
52
- klass = Class.new(R18n::TranslatedString) do
53
- def html_safe
54
- '2'
55
- end
56
- end
57
- str = klass.new('1', nil, nil)
58
-
59
- expect(str).to be_html_safe
60
- expect(str.html_safe).to eq('2')
61
- end
62
-
63
- it 'returns unescaped string if html_safe is not defined' do
64
- klass = Class.new(R18n::TranslatedString) do
65
- undef_method :html_safe if method_defined?(:html_safe)
66
- end
67
- str = klass.new('a & b', nil, nil)
68
-
69
- expect(str).not_to be_html_safe
70
- expect(str.to_s).to eq('a & b')
71
- end
72
-
73
- it 'loads use hierarchical translations' do
74
- i18n = R18n::I18n.new(%w[ru en], DIR)
75
- expect(i18n.in.another.level).to eq('Иерархический')
76
- expect(i18n[:in][:another][:level]).to eq('Иерархический')
77
- expect(i18n['in']['another']['level']).to eq('Иерархический')
78
- expect(i18n.only.english).to eq('Only in English')
79
- end
80
-
81
- it 'saves path for translation' do
82
- i18n = R18n::I18n.new('en', DIR)
83
-
84
- expect(i18n.in.another.level.path).to eq('in.another.level')
85
-
86
- expect(i18n.in.another.not.exists.path).to eq('in.another.not.exists')
87
- expect(i18n.in.another.not.exists.untranslated_path).to eq('not.exists')
88
- expect(i18n.in.another.not.exists.translated_path).to eq('in.another.')
89
-
90
- expect(i18n.not.untranslated_path).to eq('not')
91
- expect(i18n.not.translated_path).to eq('')
92
- end
93
-
94
- it 'returns translation keys' do
95
- i18n = R18n::I18n.new('en', [DIR, TWO])
96
- expect(i18n.in.translation_keys).to match_array(%w[another two])
97
- end
98
-
99
- it 'returns string with locale info' do
100
- i18n = R18n::I18n.new(%w[nolocale en], DIR)
101
- expect(i18n.one.locale).to eq(R18n::UnsupportedLocale.new('nolocale'))
102
- expect(i18n.two.locale).to eq(R18n.locale('en'))
103
- end
104
-
105
- it 'filters typed data' do
106
- en = R18n.locale('en')
107
- translation = R18n::Translation.new(
108
- en, '', locale: en, translations: {
109
- 'count' => R18n::Typed.new('pl', 1 => 'one', 'n' => 'many')
110
- }
111
- )
112
-
113
- expect(translation.count(1)).to eq('one')
114
- expect(translation.count(5)).to eq('many')
115
- end
116
-
117
- it 'returns hash of translations' do
118
- i18n = R18n::I18n.new('en', DIR)
119
- expect(i18n.in.to_hash).to eq(
120
- 'another' => { 'level' => 'Hierarchical' }
121
- )
122
- end
123
-
124
- it 'returns untranslated, when we go deeper string' do
125
- en = R18n.locale('en')
126
- translation = R18n::Translation.new(
127
- en, '', locale: en, translations: { 'a' => 'A' }
128
- )
129
-
130
- expect(translation.a.no_tr).to be_kind_of(R18n::Untranslated)
131
- expect(translation.a.no_tr.translated_path).to eq('a.')
132
- expect(translation.a.no_tr.untranslated_path).to eq('no_tr')
133
- end
134
-
135
- it 'inspects translation' do
136
- en = R18n.locale('en')
137
-
138
- translation = R18n::Translation.new(
139
- en, 'a', locale: en, translations: { 'a' => 'A' }
140
- )
141
- expect(translation.inspect).to eq('Translation `a` for en {"a"=>"A"}')
142
-
143
- translation = R18n::Translation.new(
144
- en, '', locale: en, translations: { 'a' => 'A' }
145
- )
146
- expect(translation.inspect).to eq('Translation root for en {"a"=>"A"}')
147
-
148
- translation = R18n::Translation.new(en, '')
149
- expect(translation.inspect).to eq('Translation root for en {}')
150
- end
151
-
152
- describe '#dig' do
153
- subject { R18n::I18n.new('en', DIR).in.dig(*keys) }
154
-
155
- context 'with existing keys' do
156
- let(:keys) { %w[another level] }
157
-
158
- it { is_expected.to be_translated }
159
- end
160
-
161
- context 'with non-existing keys' do
162
- let(:keys) { %w[non-existing level] }
163
-
164
- it { is_expected.not_to be_translated }
165
- end
166
- end
167
-
168
- context '`itself` key' do
169
- subject { R18n::I18n.new('en', DIR).page.itself.not_found }
170
-
171
- it { is_expected.to be_translated }
172
- it { is_expected.to eq 'Not found' }
173
- end
174
-
175
- it 'handles #to_ary' do
176
- i18n = R18n::I18n.new('en', DIR)
177
- expect([i18n.one, i18n.two].flatten).to eq [i18n.one, i18n.two]
178
- end
179
-
180
- it 'handles #to_hash' do
181
- i18n = R18n::I18n.new('en', DIR)
182
-
183
- def foo(*args, **opts)
184
- [args, opts]
185
- end
186
-
187
- expect(foo(i18n.one)).to eq [[i18n.one], {}]
188
- end
189
- end
@@ -1 +0,0 @@
1
- deep: Deep one
@@ -1,2 +0,0 @@
1
- one: No one
2
- ext: Extension
@@ -1 +0,0 @@
1
- ext: NO
@@ -1,52 +0,0 @@
1
- one: One
2
- two: Two
3
-
4
- params: Is %1 between %1 and %2?
5
-
6
- in:
7
- another:
8
- level: Hierarchical
9
-
10
- only:
11
- english: Only in English
12
-
13
- comments: !!pl
14
- 0: "no comments for %2"
15
- 1: "one comment for %2"
16
- n: "%1 comments for %2"
17
-
18
- files: !!pl
19
- 1: "1 file"
20
- n: "%1 files"
21
-
22
- your_filter: !!your another
23
- my_filter: !!my value
24
- my_tree_filter: !!my
25
- name: value
26
-
27
- html: !!escape
28
- <script>true && false</script>
29
- greater: 1 < 2 is %1
30
- no_escape: !!html
31
- <b>Warning</b>
32
- escape_params: <b>%1</b>
33
-
34
- markdown:
35
- simple: !!markdown "**Hi!**"
36
- html: !!markdown "**Hi!** <br />"
37
-
38
- textile:
39
- simple: !!textile _Hi!_
40
- html: !!textile _Hi!_<br />
41
-
42
- echo: Value is %{value}
43
- echo2: Value2 is {{value}}
44
-
45
- boolean:
46
- true: Boolean is true
47
- false: Boolean is false
48
-
49
- page:
50
- header: Title
51
- itself:
52
- not_found: Not found
@@ -1,6 +0,0 @@
1
- one: ONE
2
-
3
- entries: !!pl
4
- 1: ONE
5
- 2: TWO
6
- n: N
@@ -1,7 +0,0 @@
1
- one: Один
2
-
3
- in:
4
- another:
5
- level: Иерархический
6
-
7
- typed: !!my value
@@ -1,2 +0,0 @@
1
- in:
2
- two: Two
File without changes
File without changes
@@ -1 +0,0 @@
1
- one: British One
@@ -1 +0,0 @@
1
- one: American One
@@ -1 +0,0 @@
1
- one: One
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe R18n::Loader::YAML do
4
- before :all do
5
- R18n::Filters.add('my', :my) { |i| i }
6
- end
7
-
8
- after :all do
9
- R18n::Filters.delete(:my)
10
- end
11
-
12
- before do
13
- @loader = R18n::Loader::YAML.new(DIR)
14
- end
15
-
16
- it 'returns dir with translations' do
17
- expect(@loader.dir).to eq(DIR)
18
- end
19
-
20
- it 'equals to another YAML loader with same dir' do
21
- expect(@loader).to eq(R18n::Loader::YAML.new(DIR))
22
- expect(@loader).not_to eq(Class.new(R18n::Loader::YAML).new(DIR))
23
- end
24
-
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
- ])
31
- end
32
-
33
- it 'loads translation' do
34
- expect(@loader.load(R18n.locale('ru'))).to eq(
35
- 'one' => 'Один',
36
- 'in' => { 'another' => { 'level' => 'Иерархический' } },
37
- 'typed' => R18n::Typed.new('my', 'value')
38
- )
39
- end
40
-
41
- it 'returns hash by dir' do
42
- expect(@loader.hash).to eq(R18n::Loader::YAML.new(DIR).hash)
43
- end
44
-
45
- it 'loads in dir recursively' do
46
- loader = R18n::Loader::YAML.new(TRANSLATIONS)
47
- expect(loader.available).to match_array([
48
- R18n.locale('ru'),
49
- R18n.locale('en'),
50
- R18n.locale('en-us'),
51
- R18n.locale('en-gb'),
52
- R18n.locale('fr'),
53
- R18n.locale('notransl'),
54
- R18n.locale('nolocale')
55
- ])
56
-
57
- translation = loader.load(R18n.locale('en'))
58
- expect(translation['two']).to eq('Two')
59
- expect(translation['in']['two']).to eq('Two')
60
- expect(translation['ext']).to eq('Extension')
61
- expect(translation['deep']).to eq('Deep one')
62
- end
63
- end