i18n-js 3.2.1 → 4.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +4 -0
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +73 -0
- data/.gitignore +13 -7
- data/.rubocop.yml +19 -0
- data/CHANGELOG.md +45 -386
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/MIGRATING_FROM_V3_TO_V4.md +191 -0
- data/README.md +439 -791
- data/Rakefile +10 -20
- data/bin/release +81 -0
- data/exe/i18n +5 -0
- data/i18n-js.gemspec +51 -29
- data/lib/guard/i18n-js/templates/Guardfile +10 -0
- data/lib/guard/i18n-js/version.rb +13 -0
- data/lib/guard/i18n-js.rb +95 -0
- data/lib/i18n-js/clean_hash.rb +13 -0
- data/lib/i18n-js/cli/check_command.rb +17 -0
- data/lib/i18n-js/cli/command.rb +79 -0
- data/lib/i18n-js/cli/export_command.rb +95 -0
- data/lib/i18n-js/cli/init_command.rb +52 -0
- data/lib/i18n-js/cli/lint_scripts_command.rb +157 -0
- data/lib/i18n-js/cli/lint_translations_command.rb +155 -0
- data/lib/i18n-js/cli/plugins_command.rb +67 -0
- data/lib/i18n-js/cli/ui.rb +64 -0
- data/lib/i18n-js/cli/version_command.rb +18 -0
- data/lib/i18n-js/cli.rb +66 -0
- data/lib/i18n-js/embed_fallback_translations_plugin.rb +70 -0
- data/lib/i18n-js/export_files_plugin.rb +103 -0
- data/lib/i18n-js/lint.js +150645 -0
- data/lib/i18n-js/lint.ts +196 -0
- data/lib/i18n-js/listen.rb +96 -0
- data/lib/i18n-js/plugin.rb +103 -0
- data/lib/i18n-js/schema.rb +216 -0
- data/lib/i18n-js/sort_hash.rb +12 -0
- data/lib/i18n-js/version.rb +5 -0
- data/lib/i18n-js.rb +107 -1
- data/package.json +5 -20
- metadata +153 -181
- data/.editorconfig +0 -24
- data/.npmignore +0 -27
- data/.travis.yml +0 -36
- data/Appraisals +0 -32
- data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
- data/app/assets/javascripts/i18n/shims.js +0 -208
- data/app/assets/javascripts/i18n/translations.js +0 -3
- data/app/assets/javascripts/i18n.js +0 -1077
- data/gemfiles/i18n_0_6.gemfile +0 -7
- data/gemfiles/i18n_0_7.gemfile +0 -7
- data/gemfiles/i18n_0_8.gemfile +0 -7
- data/gemfiles/i18n_0_9.gemfile +0 -7
- data/gemfiles/i18n_1_0.gemfile +0 -7
- data/gemfiles/i18n_1_1.gemfile +0 -7
- data/gemfiles/i18n_1_2.gemfile +0 -7
- data/gemfiles/i18n_1_3.gemfile +0 -7
- data/gemfiles/i18n_1_4.gemfile +0 -7
- data/gemfiles/i18n_1_5.gemfile +0 -7
- data/lib/i18n/js/dependencies.rb +0 -59
- data/lib/i18n/js/engine.rb +0 -87
- data/lib/i18n/js/fallback_locales.rb +0 -70
- data/lib/i18n/js/formatters/base.rb +0 -23
- data/lib/i18n/js/formatters/js.rb +0 -31
- data/lib/i18n/js/formatters/json.rb +0 -13
- data/lib/i18n/js/middleware.rb +0 -82
- data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
- data/lib/i18n/js/segment.rb +0 -75
- data/lib/i18n/js/utils.rb +0 -65
- data/lib/i18n/js/version.rb +0 -7
- data/lib/i18n/js.rb +0 -259
- data/lib/rails/generators/i18n/js/config/config_generator.rb +0 -19
- data/lib/rails/generators/i18n/js/config/templates/i18n-js.yml +0 -27
- data/lib/tasks/export.rake +0 -8
- data/spec/fixtures/custom_path.yml +0 -5
- data/spec/fixtures/default.yml +0 -5
- data/spec/fixtures/erb.yml +0 -5
- data/spec/fixtures/except_condition.yml +0 -7
- data/spec/fixtures/js_export_dir_custom.yml +0 -7
- data/spec/fixtures/js_export_dir_none.yml +0 -6
- data/spec/fixtures/js_extend_parent.yml +0 -6
- data/spec/fixtures/js_extend_segment.yml +0 -6
- data/spec/fixtures/js_file_per_locale.yml +0 -7
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +0 -6
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +0 -4
- data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +0 -4
- data/spec/fixtures/js_file_with_namespace_and_pretty_print.yml +0 -7
- data/spec/fixtures/js_sort_translation_keys_false.yml +0 -6
- data/spec/fixtures/js_sort_translation_keys_true.yml +0 -6
- data/spec/fixtures/json_only.yml +0 -18
- data/spec/fixtures/locales.yml +0 -95
- data/spec/fixtures/merge_plurals.yml +0 -6
- data/spec/fixtures/multiple_conditions.yml +0 -7
- data/spec/fixtures/multiple_conditions_per_locale.yml +0 -7
- data/spec/fixtures/multiple_files.yml +0 -7
- data/spec/fixtures/no_config.yml +0 -2
- data/spec/fixtures/no_scope.yml +0 -4
- data/spec/fixtures/simple_scope.yml +0 -5
- data/spec/js/currency.spec.js +0 -62
- data/spec/js/current_locale.spec.js +0 -19
- data/spec/js/dates.spec.js +0 -265
- data/spec/js/defaults.spec.js +0 -31
- data/spec/js/extend.spec.js +0 -110
- data/spec/js/interpolation.spec.js +0 -124
- data/spec/js/jasmine/MIT.LICENSE +0 -20
- data/spec/js/jasmine/jasmine-html.js +0 -190
- data/spec/js/jasmine/jasmine.css +0 -166
- data/spec/js/jasmine/jasmine.js +0 -2476
- data/spec/js/jasmine/jasmine_favicon.png +0 -0
- data/spec/js/locales.spec.js +0 -31
- data/spec/js/localization.spec.js +0 -48
- data/spec/js/numbers.spec.js +0 -170
- data/spec/js/placeholder.spec.js +0 -24
- data/spec/js/pluralization.spec.js +0 -211
- data/spec/js/prepare_options.spec.js +0 -41
- data/spec/js/require.js +0 -2083
- data/spec/js/specs.html +0 -49
- data/spec/js/specs_requirejs.html +0 -72
- data/spec/js/translate.spec.js +0 -284
- data/spec/js/translations.js +0 -163
- data/spec/js/utility_functions.spec.js +0 -20
- data/spec/ruby/i18n/js/fallback_locales_spec.rb +0 -84
- data/spec/ruby/i18n/js/segment_spec.rb +0 -219
- data/spec/ruby/i18n/js/utils_spec.rb +0 -106
- data/spec/ruby/i18n/js_spec.rb +0 -663
- data/spec/spec_helper.rb +0 -79
- data/yarn.lock +0 -131
@@ -1,219 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe I18n::JS::Segment do
|
4
|
-
|
5
|
-
let(:file) { "tmp/i18n-js/segment.js" }
|
6
|
-
let(:translations){ { en: { "test" => "Test" }, fr: { "test" => "Test2" } } }
|
7
|
-
let(:namespace) { "MyNamespace" }
|
8
|
-
let(:pretty_print){ nil }
|
9
|
-
let(:json_only) { nil }
|
10
|
-
let(:js_extend) { nil }
|
11
|
-
let(:sort_translation_keys){ nil }
|
12
|
-
let(:options) { { namespace: namespace,
|
13
|
-
pretty_print: pretty_print,
|
14
|
-
json_only: json_only,
|
15
|
-
js_extend: js_extend,
|
16
|
-
sort_translation_keys: sort_translation_keys }.delete_if{|k,v| v.nil?} }
|
17
|
-
subject { I18n::JS::Segment.new(file, translations, options) }
|
18
|
-
|
19
|
-
describe ".new" do
|
20
|
-
|
21
|
-
it "should persist the file path variable" do
|
22
|
-
expect(subject.file).to eql("tmp/i18n-js/segment.js")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should persist the translations variable" do
|
26
|
-
expect(subject.translations).to eql(translations)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should persist the namespace variable" do
|
30
|
-
expect(subject.namespace).to eql("MyNamespace")
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when namespace is nil" do
|
34
|
-
let(:namespace){ nil }
|
35
|
-
|
36
|
-
it "should default namespace to `I18n`" do
|
37
|
-
expect(subject.namespace).to eql("I18n")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when namespace is not set" do
|
42
|
-
subject { I18n::JS::Segment.new(file, translations) }
|
43
|
-
|
44
|
-
it "should default namespace to `I18n`" do
|
45
|
-
expect(subject.namespace).to eql("I18n")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when pretty_print is nil" do
|
50
|
-
it "should set pretty_print to false" do
|
51
|
-
expect(subject.pretty_print).to be false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when pretty_print is truthy" do
|
56
|
-
let(:pretty_print){ 1 }
|
57
|
-
|
58
|
-
it "should set pretty_print to true" do
|
59
|
-
expect(subject.pretty_print).to be true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#saving!" do
|
65
|
-
before { allow(I18n::JS).to receive(:export_i18n_js_dir_path).and_return(temp_path) }
|
66
|
-
|
67
|
-
context "when json_only is true with locale" do
|
68
|
-
let(:file){ "tmp/i18n-js/%{locale}.js" }
|
69
|
-
let(:json_only){ true }
|
70
|
-
|
71
|
-
it 'should output JSON files per locale' do
|
72
|
-
subject.save!
|
73
|
-
file_should_exist "en.js"
|
74
|
-
file_should_exist "fr.js"
|
75
|
-
|
76
|
-
expect(File.read(File.join(temp_path, "en.js"))).to eql(
|
77
|
-
%Q({"en":{"test":"Test"}})
|
78
|
-
)
|
79
|
-
|
80
|
-
expect(File.read(File.join(temp_path, "fr.js"))).to eql(
|
81
|
-
%Q({"fr":{"test":"Test2"}})
|
82
|
-
)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when json_only is true without locale" do
|
87
|
-
let(:file){ "tmp/i18n-js/segment.js" }
|
88
|
-
let(:json_only){ true }
|
89
|
-
|
90
|
-
it 'should output one JSON file for all locales' do
|
91
|
-
subject.save!
|
92
|
-
file_should_exist "segment.js"
|
93
|
-
|
94
|
-
expect(File.read(File.join(temp_path, "segment.js"))).to eql(
|
95
|
-
%Q({"en":{"test":"Test"},"fr":{"test":"Test2"}})
|
96
|
-
)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "when json_only and pretty print are true" do
|
101
|
-
let(:file){ "tmp/i18n-js/segment.js" }
|
102
|
-
let(:json_only){ true }
|
103
|
-
let(:pretty_print){ true }
|
104
|
-
|
105
|
-
it 'should output one JSON file for all locales' do
|
106
|
-
subject.save!
|
107
|
-
file_should_exist "segment.js"
|
108
|
-
|
109
|
-
expect(File.read(File.join(temp_path, "segment.js"))).to eql <<-EOS
|
110
|
-
{
|
111
|
-
"en": {
|
112
|
-
"test": "Test"
|
113
|
-
},
|
114
|
-
"fr": {
|
115
|
-
"test": "Test2"
|
116
|
-
}
|
117
|
-
}
|
118
|
-
EOS
|
119
|
-
.chomp
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "#save!" do
|
125
|
-
before { allow(I18n::JS).to receive(:export_i18n_js_dir_path).and_return(temp_path) }
|
126
|
-
before { subject.save! }
|
127
|
-
|
128
|
-
context "when file does not include %{locale}" do
|
129
|
-
it "should write the file" do
|
130
|
-
file_should_exist "segment.js"
|
131
|
-
|
132
|
-
expect(File.open(File.join(temp_path, "segment.js")){|f| f.read}).to eql <<-EOF
|
133
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
134
|
-
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"test":"Test"});
|
135
|
-
MyNamespace.translations["fr"] = I18n.extend((MyNamespace.translations["fr"] || {}), {"test":"Test2"});
|
136
|
-
EOF
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "when file includes %{locale}" do
|
141
|
-
let(:file){ "tmp/i18n-js/%{locale}.js" }
|
142
|
-
|
143
|
-
it "should write files" do
|
144
|
-
file_should_exist "en.js"
|
145
|
-
file_should_exist "fr.js"
|
146
|
-
|
147
|
-
expect(File.open(File.join(temp_path, "en.js")){|f| f.read}).to eql <<-EOF
|
148
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
149
|
-
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"test":"Test"});
|
150
|
-
EOF
|
151
|
-
|
152
|
-
expect(File.open(File.join(temp_path, "fr.js")){|f| f.read}).to eql <<-EOF
|
153
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
154
|
-
MyNamespace.translations["fr"] = I18n.extend((MyNamespace.translations["fr"] || {}), {"test":"Test2"});
|
155
|
-
EOF
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context "when js_extend is true" do
|
160
|
-
let(:js_extend){ true }
|
161
|
-
|
162
|
-
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
163
|
-
|
164
|
-
it 'should output the keys as sorted' do
|
165
|
-
file_should_exist "segment.js"
|
166
|
-
|
167
|
-
expect(File.open(File.join(temp_path, "segment.js")){|f| f.read}).to eql <<-EOF
|
168
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
169
|
-
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"a":"Test","b":"Test"});
|
170
|
-
EOF
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context "when js_extend is false" do
|
175
|
-
let(:js_extend){ false }
|
176
|
-
|
177
|
-
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
178
|
-
|
179
|
-
it 'should output the keys as sorted' do
|
180
|
-
file_should_exist "segment.js"
|
181
|
-
|
182
|
-
expect(File.open(File.join(temp_path, "segment.js")){|f| f.read}).to eql <<-EOF
|
183
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
184
|
-
MyNamespace.translations["en"] = {"a":"Test","b":"Test"};
|
185
|
-
EOF
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context "when sort_translation_keys is true" do
|
190
|
-
let(:sort_translation_keys){ true }
|
191
|
-
|
192
|
-
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
193
|
-
|
194
|
-
it 'should output the keys as sorted' do
|
195
|
-
file_should_exist "segment.js"
|
196
|
-
|
197
|
-
expect(File.open(File.join(temp_path, "segment.js")){|f| f.read}).to eql <<-EOF
|
198
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
199
|
-
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"a":"Test","b":"Test"});
|
200
|
-
EOF
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context "when sort_translation_keys is false" do
|
205
|
-
let(:sort_translation_keys){ false }
|
206
|
-
|
207
|
-
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
208
|
-
|
209
|
-
it 'should output the keys as sorted' do
|
210
|
-
file_should_exist "segment.js"
|
211
|
-
|
212
|
-
expect(File.open(File.join(temp_path, "segment.js")){|f| f.read}).to eql <<-EOF
|
213
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
214
|
-
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"b":"Test","a":"Test"});
|
215
|
-
EOF
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe I18n::JS::Utils do
|
4
|
-
|
5
|
-
describe ".strip_keys_with_nil_values" do
|
6
|
-
subject { described_class.strip_keys_with_nil_values(input_hash) }
|
7
|
-
|
8
|
-
context 'when input_hash does NOT contain nil value' do
|
9
|
-
let(:input_hash) { {a: 1, b: { c: 2 }} }
|
10
|
-
let(:expected_hash) { input_hash }
|
11
|
-
|
12
|
-
it 'returns the original input' do
|
13
|
-
is_expected.to eq expected_hash
|
14
|
-
end
|
15
|
-
end
|
16
|
-
context 'when input_hash does contain nil value' do
|
17
|
-
let(:input_hash) { {a: 1, b: { c: 2, d: nil }, e: { f: nil }} }
|
18
|
-
let(:expected_hash) { {a: 1, b: { c: 2 }, e: {}} }
|
19
|
-
|
20
|
-
it 'returns the original input with nil values removed' do
|
21
|
-
is_expected.to eq expected_hash
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "hash merging" do
|
27
|
-
it "performs a deep merge" do
|
28
|
-
target = {:a => {:b => 1}}
|
29
|
-
result = described_class.deep_merge(target, {:a => {:c => 2}})
|
30
|
-
|
31
|
-
expect(result[:a]).to eql({:b => 1, :c => 2})
|
32
|
-
end
|
33
|
-
|
34
|
-
it "performs a banged deep merge" do
|
35
|
-
target = {:a => {:b => 1}}
|
36
|
-
described_class.deep_merge!(target, {:a => {:c => 2}})
|
37
|
-
|
38
|
-
expect(target[:a]).to eql({:b => 1, :c => 2})
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe ".deep_reject" do
|
43
|
-
it "performs a deep keys rejection" do
|
44
|
-
hash = {:a => {:b => 1}}
|
45
|
-
|
46
|
-
result = described_class.deep_reject(hash) { |k, v| k == :b }
|
47
|
-
|
48
|
-
expect(result).to eql({:a => {}})
|
49
|
-
end
|
50
|
-
|
51
|
-
it "performs a deep keys rejection prunning the whole tree if necessary" do
|
52
|
-
hash = {:a => {:b => {:c => {:d => 1, :e => 2}}}}
|
53
|
-
|
54
|
-
result = described_class.deep_reject(hash) { |k, v| k == :b }
|
55
|
-
|
56
|
-
expect(result).to eql({:a => {}})
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
it "performs a deep keys rejection without changing the original hash" do
|
61
|
-
hash = {:a => {:b => 1, :c => 2}}
|
62
|
-
|
63
|
-
result = described_class.deep_reject(hash) { |k, v| k == :b }
|
64
|
-
|
65
|
-
expect(result).to eql({:a => {:c => 2}})
|
66
|
-
expect(hash).to eql({:a => {:b => 1, :c => 2}})
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe ".deep_key_sort" do
|
71
|
-
let(:unsorted_hash) { {:z => {:b => 1, :a => 2}, :y => 3} }
|
72
|
-
subject(:sorting) { described_class.deep_key_sort(unsorted_hash) }
|
73
|
-
|
74
|
-
it "performs a deep keys sort without changing the original hash" do
|
75
|
-
should eql({:y => 3, :z => {:a => 2, :b => 1}})
|
76
|
-
expect(unsorted_hash).to eql({:z => {:b => 1, :a => 2}, :y => 3})
|
77
|
-
end
|
78
|
-
|
79
|
-
# Idea from gem `rails_admin`
|
80
|
-
context "when hash contain non-Symbol as key" do
|
81
|
-
let(:unsorted_hash) { {:z => {1 => 1, true => 2}, :y => 3} }
|
82
|
-
|
83
|
-
it "performs a deep keys sort without error" do
|
84
|
-
expect{ sorting }.to_not raise_error
|
85
|
-
end
|
86
|
-
it "converts keys to symbols" do
|
87
|
-
should eql({:y => 3, :z => {1 => 1, true => 2}})
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe ".scopes_match?" do
|
93
|
-
it "performs a comparison of literal scopes" do
|
94
|
-
expect(described_class.scopes_match?([:a, :b], [:a, :b, :c])).to_not eql true
|
95
|
-
expect(described_class.scopes_match?([:a, :b, :c], [:a, :b, :c])).to eql true
|
96
|
-
expect(described_class.scopes_match?([:a, :b, :c], [:a, :b, :d])).to_not eql true
|
97
|
-
end
|
98
|
-
|
99
|
-
it "performs a comparison of wildcard scopes" do
|
100
|
-
expect(described_class.scopes_match?([:a, '*'], [:a, :b, :c])).to_not eql true
|
101
|
-
expect(described_class.scopes_match?([:a, '*', :c], [:a, :b, :c])).to eql true
|
102
|
-
expect(described_class.scopes_match?([:a, :b, :c], [:a, '*', :c])).to eql true
|
103
|
-
expect(described_class.scopes_match?([:a, :b, :c], [:a, '*', '*'])).to eql true
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|