r18n-core 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.rspec +1 -1
  3. data/ChangeLog.md +6 -1
  4. data/README.md +1 -20
  5. data/Rakefile +5 -3
  6. data/lib/r18n-core.rb +55 -55
  7. data/lib/r18n-core/filter_list.rb +34 -36
  8. data/lib/r18n-core/filters.rb +68 -51
  9. data/lib/r18n-core/helpers.rb +17 -17
  10. data/lib/r18n-core/i18n.rb +46 -39
  11. data/lib/r18n-core/locale.rb +79 -70
  12. data/lib/r18n-core/translated.rb +65 -66
  13. data/lib/r18n-core/translated_string.rb +24 -24
  14. data/lib/r18n-core/translation.rb +31 -30
  15. data/lib/r18n-core/unsupported_locale.rb +22 -24
  16. data/lib/r18n-core/untranslated.rb +35 -33
  17. data/lib/r18n-core/utils.rb +26 -25
  18. data/lib/r18n-core/version.rb +4 -1
  19. data/lib/r18n-core/yaml_loader.rb +26 -25
  20. data/lib/r18n-core/yaml_methods.rb +25 -28
  21. data/locales/af.rb +15 -8
  22. data/locales/az.rb +19 -12
  23. data/locales/bg.rb +16 -9
  24. data/locales/ca.rb +16 -9
  25. data/locales/cs.rb +27 -20
  26. data/locales/da.rb +15 -8
  27. data/locales/de.rb +16 -9
  28. data/locales/en-au.rb +10 -5
  29. data/locales/en-gb.rb +12 -5
  30. data/locales/en-us.rb +12 -5
  31. data/locales/en.rb +29 -22
  32. data/locales/eo.rb +14 -7
  33. data/locales/es-us.rb +12 -5
  34. data/locales/es.rb +14 -7
  35. data/locales/fa.rb +48 -32
  36. data/locales/fi.rb +19 -12
  37. data/locales/fr.rb +22 -15
  38. data/locales/gl.rb +15 -8
  39. data/locales/hr.rb +24 -17
  40. data/locales/hu.rb +28 -21
  41. data/locales/id.rb +14 -7
  42. data/locales/it.rb +21 -14
  43. data/locales/ja.rb +15 -8
  44. data/locales/kk.rb +17 -10
  45. data/locales/ko.rb +15 -9
  46. data/locales/lv.rb +24 -17
  47. data/locales/mn.rb +10 -3
  48. data/locales/nb.rb +15 -8
  49. data/locales/nl.rb +15 -8
  50. data/locales/no.rb +11 -16
  51. data/locales/pl.rb +26 -19
  52. data/locales/pt-br.rb +12 -5
  53. data/locales/pt.rb +17 -10
  54. data/locales/ru.rb +26 -19
  55. data/locales/sk.rb +27 -20
  56. data/locales/sr-latn.rb +27 -22
  57. data/locales/sv-se.rb +15 -8
  58. data/locales/th.rb +27 -20
  59. data/locales/tr.rb +16 -9
  60. data/locales/uk.rb +19 -12
  61. data/locales/vi.rb +14 -7
  62. data/locales/zh-cn.rb +12 -5
  63. data/locales/zh-tw.rb +15 -8
  64. data/locales/zh.rb +14 -7
  65. data/r18n-core.gemspec +5 -3
  66. data/spec/filters_spec.rb +71 -67
  67. data/spec/i18n_spec.rb +73 -51
  68. data/spec/locale_spec.rb +73 -68
  69. data/spec/locales/cs_spec.rb +2 -2
  70. data/spec/locales/en-us_spec.rb +9 -9
  71. data/spec/locales/en_spec.rb +2 -2
  72. data/spec/locales/fa_spec.rb +3 -3
  73. data/spec/locales/fr_spec.rb +2 -2
  74. data/spec/locales/hu_spec.rb +7 -7
  75. data/spec/locales/it_spec.rb +3 -3
  76. data/spec/locales/no_spec.rb +9 -0
  77. data/spec/locales/pl_spec.rb +2 -2
  78. data/spec/locales/ru_spec.rb +2 -2
  79. data/spec/locales/sk_spec.rb +2 -2
  80. data/spec/locales/th_spec.rb +2 -2
  81. data/spec/locales/vi_spec.rb +2 -2
  82. data/spec/r18n_spec.rb +44 -38
  83. data/spec/spec_helper.rb +13 -9
  84. data/spec/translated_spec.rb +48 -31
  85. data/spec/translation_spec.rb +29 -27
  86. data/spec/translations/general/en.yml +0 -2
  87. data/spec/yaml_loader_spec.rb +22 -18
  88. metadata +5 -3
@@ -1,7 +1,6 @@
1
- require File.expand_path('../spec_helper', __FILE__)
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 "returns strings which can be used as normal strings" do
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 "returns strings compatible with activesupport json encoding" do
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 "returns strings by Boolean keys (true, false)" do
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 "returns html escaped string if html_safe is defined" do
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 "returns unescaped string if html_safe is not defined" do
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 "loads use hierarchical translations" do
75
- i18n = R18n::I18n.new(['ru', 'en'], DIR)
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 "saves path for translation" do
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 "returns translation keys" do
94
+ it 'returns translation keys' do
96
95
  i18n = R18n::I18n.new('en', [DIR, TWO])
97
- expect(i18n.in.translation_keys).to match_array(['another', 'two'])
96
+ expect(i18n.in.translation_keys).to match_array(%w[another two])
98
97
  end
99
98
 
100
- it "returns string with locale info" do
101
- i18n = R18n::I18n.new(['nolocale', 'en'], DIR)
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 "filters typed data" do
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', { 1 => 'one', 'n' => 'many' }) })
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 "returns hash of translations" do
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 "returns untranslated, when we go deeper string" do
121
+ it 'returns untranslated, when we go deeper string' do
123
122
  en = R18n.locale('en')
124
- translation = R18n::Translation.new(en, '',
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 "inspects translation" do
132
+ it 'inspects translation' do
133
133
  en = R18n.locale('en')
134
134
 
135
- translation = R18n::Translation.new(en, 'a',
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(en, '',
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, '')
@@ -10,8 +10,6 @@ in:
10
10
  only:
11
11
  english: Only in English
12
12
 
13
- sum: !!proc "|x, y| x + y"
14
-
15
13
  comments: !!pl
16
14
  0: "no comments for %2"
17
15
  1: "one comment for %2"
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
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 "returns dir with translations" do
17
- expect(@loader.dir).to eq(DIR.expand_path.to_s)
16
+ it 'returns dir with translations' do
17
+ expect(@loader.dir).to eq(DIR)
18
18
  end
19
19
 
20
- it "equals to another YAML loader with same dir" do
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 "returns all available translations" do
26
- expect(@loader.available).to match_array([R18n.locale('ru'),
27
- R18n.locale('en'),
28
- R18n.locale('nolocale')])
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 "loads translation" do
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 "returns hash by dir" do
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 "loads in dir recursively" do
45
+ it 'loads in dir recursively' do
44
46
  loader = R18n::Loader::YAML.new(TRANSLATIONS)
45
- expect(loader.available).to match_array([R18n.locale('ru'),
46
- R18n.locale('en'),
47
- R18n.locale('fr'),
48
- R18n.locale('notransl'),
49
- R18n.locale('nolocale')])
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: 2.2.0
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: 2017-12-22 00:00:00.000000000 Z
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.5.2.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