r18n-core 3.1.1 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +398 -0
  3. data/README.md +63 -47
  4. data/base/cy.yml +34 -0
  5. data/lib/r18n-core.rb +37 -38
  6. data/lib/r18n-core/filter_list.rb +21 -13
  7. data/lib/r18n-core/filters.rb +43 -48
  8. data/lib/r18n-core/helpers.rb +2 -2
  9. data/lib/r18n-core/i18n.rb +70 -78
  10. data/lib/r18n-core/locale.rb +137 -107
  11. data/lib/r18n-core/locales/af.rb +36 -0
  12. data/lib/r18n-core/locales/az.rb +38 -0
  13. data/lib/r18n-core/locales/bg.rb +29 -0
  14. data/{locales → lib/r18n-core/locales}/ca.rb +9 -6
  15. data/{locales → lib/r18n-core/locales}/cs.rb +15 -11
  16. data/lib/r18n-core/locales/cy.rb +50 -0
  17. data/{locales → lib/r18n-core/locales}/da.rb +10 -7
  18. data/lib/r18n-core/locales/de.rb +33 -0
  19. data/{locales → lib/r18n-core/locales}/en-au.rb +2 -2
  20. data/{locales → lib/r18n-core/locales}/en-gb.rb +2 -2
  21. data/{locales → lib/r18n-core/locales}/en-us.rb +4 -3
  22. data/lib/r18n-core/locales/en.rb +51 -0
  23. data/{locales → lib/r18n-core/locales}/eo.rb +6 -4
  24. data/lib/r18n-core/locales/es-cl.rb +16 -0
  25. data/{locales → lib/r18n-core/locales}/es-us.rb +5 -4
  26. data/{locales → lib/r18n-core/locales}/es.rb +7 -3
  27. data/{locales → lib/r18n-core/locales}/fa.rb +2 -2
  28. data/lib/r18n-core/locales/fi.rb +39 -0
  29. data/lib/r18n-core/locales/fr.rb +39 -0
  30. data/{locales → lib/r18n-core/locales}/gl.rb +5 -3
  31. data/{locales → lib/r18n-core/locales}/hr.rb +13 -10
  32. data/{locales → lib/r18n-core/locales}/hu.rb +10 -7
  33. data/{locales → lib/r18n-core/locales}/id.rb +8 -4
  34. data/lib/r18n-core/locales/it.rb +37 -0
  35. data/{locales → lib/r18n-core/locales}/ja.rb +5 -4
  36. data/{locales → lib/r18n-core/locales}/kk.rb +12 -8
  37. data/{locales → lib/r18n-core/locales}/ko.rb +0 -0
  38. data/lib/r18n-core/locales/lv.rb +46 -0
  39. data/lib/r18n-core/locales/mn.rb +30 -0
  40. data/{locales → lib/r18n-core/locales}/nb.rb +6 -4
  41. data/lib/r18n-core/locales/nl.rb +31 -0
  42. data/{locales → lib/r18n-core/locales}/no.rb +0 -0
  43. data/lib/r18n-core/locales/pl.rb +45 -0
  44. data/{locales → lib/r18n-core/locales}/pt-br.rb +1 -1
  45. data/lib/r18n-core/locales/pt.rb +37 -0
  46. data/lib/r18n-core/locales/ru.rb +46 -0
  47. data/{locales → lib/r18n-core/locales}/sk.rb +13 -9
  48. data/{locales → lib/r18n-core/locales}/sr-latn.rb +10 -8
  49. data/{locales → lib/r18n-core/locales}/sv-se.rb +7 -5
  50. data/lib/r18n-core/locales/th.rb +41 -0
  51. data/{locales → lib/r18n-core/locales}/tr.rb +7 -6
  52. data/lib/r18n-core/locales/uk.rb +31 -0
  53. data/lib/r18n-core/locales/vi.rb +37 -0
  54. data/{locales → lib/r18n-core/locales}/zh-cn.rb +2 -2
  55. data/{locales → lib/r18n-core/locales}/zh-tw.rb +4 -4
  56. data/{locales → lib/r18n-core/locales}/zh.rb +7 -4
  57. data/lib/r18n-core/translated.rb +38 -37
  58. data/lib/r18n-core/translated_string.rb +19 -8
  59. data/lib/r18n-core/translation.rb +24 -19
  60. data/lib/r18n-core/unsupported_locale.rb +14 -6
  61. data/lib/r18n-core/untranslated.rb +23 -7
  62. data/lib/r18n-core/utils.rb +19 -23
  63. data/lib/r18n-core/version.rb +1 -1
  64. data/lib/r18n-core/yaml_loader.rb +17 -13
  65. data/lib/r18n-core/yaml_methods.rb +3 -1
  66. metadata +245 -118
  67. data/.rspec +0 -1
  68. data/Rakefile +0 -13
  69. data/locales/af.rb +0 -32
  70. data/locales/az.rb +0 -34
  71. data/locales/bg.rb +0 -25
  72. data/locales/de.rb +0 -29
  73. data/locales/en.rb +0 -48
  74. data/locales/fi.rb +0 -35
  75. data/locales/fr.rb +0 -35
  76. data/locales/it.rb +0 -34
  77. data/locales/lv.rb +0 -41
  78. data/locales/mn.rb +0 -27
  79. data/locales/nl.rb +0 -28
  80. data/locales/pl.rb +0 -40
  81. data/locales/pt.rb +0 -29
  82. data/locales/ru.rb +0 -41
  83. data/locales/th.rb +0 -37
  84. data/locales/uk.rb +0 -27
  85. data/locales/vi.rb +0 -33
  86. data/r18n-core.gemspec +0 -29
  87. data/spec/filters_spec.rb +0 -324
  88. data/spec/i18n_spec.rb +0 -260
  89. data/spec/locale_spec.rb +0 -216
  90. data/spec/locales/cs_spec.rb +0 -23
  91. data/spec/locales/en-us_spec.rb +0 -13
  92. data/spec/locales/en_spec.rb +0 -13
  93. data/spec/locales/fa_spec.rb +0 -10
  94. data/spec/locales/fr_spec.rb +0 -9
  95. data/spec/locales/hu_spec.rb +0 -17
  96. data/spec/locales/it_spec.rb +0 -10
  97. data/spec/locales/no_spec.rb +0 -9
  98. data/spec/locales/pl_spec.rb +0 -23
  99. data/spec/locales/ru_spec.rb +0 -23
  100. data/spec/locales/sk_spec.rb +0 -23
  101. data/spec/locales/th_spec.rb +0 -9
  102. data/spec/locales/vi_spec.rb +0 -8
  103. data/spec/r18n_spec.rb +0 -172
  104. data/spec/spec_helper.rb +0 -41
  105. data/spec/translated_spec.rb +0 -163
  106. data/spec/translation_spec.rb +0 -164
  107. data/spec/translations/extension/deep/en.yml +0 -1
  108. data/spec/translations/extension/en.yml +0 -2
  109. data/spec/translations/extension/notransl.yml +0 -1
  110. data/spec/translations/general/en.yml +0 -47
  111. data/spec/translations/general/nolocale.yml +0 -6
  112. data/spec/translations/general/ru.yml +0 -7
  113. data/spec/translations/two/en.yml +0 -2
  114. data/spec/translations/two/fr.yml +0 -0
  115. data/spec/yaml_loader_spec.rb +0 -61
@@ -1,164 +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(en, '', locale: en, translations:
108
- { 'count' => R18n::Typed.new('pl', 1 => 'one', 'n' => 'many') })
109
-
110
- expect(translation.count(1)).to eq('one')
111
- expect(translation.count(5)).to eq('many')
112
- end
113
-
114
- it 'returns hash of translations' do
115
- i18n = R18n::I18n.new('en', DIR)
116
- expect(i18n.in.to_hash).to eq(
117
- 'another' => { 'level' => 'Hierarchical' }
118
- )
119
- end
120
-
121
- it 'returns untranslated, when we go deeper string' do
122
- en = R18n.locale('en')
123
- translation = R18n::Translation.new(
124
- en, '', locale: en, translations: { 'a' => 'A' }
125
- )
126
-
127
- expect(translation.a.no_tr).to be_kind_of(R18n::Untranslated)
128
- expect(translation.a.no_tr.translated_path).to eq('a.')
129
- expect(translation.a.no_tr.untranslated_path).to eq('no_tr')
130
- end
131
-
132
- it 'inspects translation' do
133
- en = R18n.locale('en')
134
-
135
- translation = R18n::Translation.new(
136
- en, 'a', locale: en, translations: { 'a' => 'A' }
137
- )
138
- expect(translation.inspect).to eq('Translation `a` for en {"a"=>"A"}')
139
-
140
- translation = R18n::Translation.new(
141
- en, '', locale: en, translations: { 'a' => 'A' }
142
- )
143
- expect(translation.inspect).to eq('Translation root for en {"a"=>"A"}')
144
-
145
- translation = R18n::Translation.new(en, '')
146
- expect(translation.inspect).to eq('Translation root for en {}')
147
- end
148
-
149
- describe '#dig' do
150
- subject { R18n::I18n.new('en', DIR).in.dig(*keys) }
151
-
152
- context 'with existing keys' do
153
- let(:keys) { %w[another level] }
154
-
155
- it { is_expected.to be_translated }
156
- end
157
-
158
- context 'with non-existing keys' do
159
- let(:keys) { %w[non-existing level] }
160
-
161
- it { is_expected.not_to be_translated }
162
- end
163
- end
164
- 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,47 +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
@@ -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
@@ -1,61 +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('fr'),
51
- R18n.locale('notransl'),
52
- R18n.locale('nolocale')
53
- ])
54
-
55
- translation = loader.load(R18n.locale('en'))
56
- expect(translation['two']).to eq('Two')
57
- expect(translation['in']['two']).to eq('Two')
58
- expect(translation['ext']).to eq('Extension')
59
- expect(translation['deep']).to eq('Deep one')
60
- end
61
- end