i18n-js 3.0.0.rc8 → 3.0.0.rc9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Jasmine Spec Runner</title>
6
+ <link rel="stylesheet" href="jasmine/jasmine.css" type="text/css">
7
+ </head>
8
+
9
+ <body>
10
+ <!-- load jasmine -->
11
+ <script type="text/javascript" src="jasmine/jasmine.js"></script>
12
+ <script type="text/javascript" src="jasmine/jasmine-html.js"></script>
13
+
14
+ <!-- load your javascript files -->
15
+ <script type="text/javascript" src="require.js"></script>
16
+
17
+ <script type="text/javascript">
18
+ // Prepare requirejs shims to wrap each test so that it will work with the
19
+ // require syntax loading
20
+ var testScripts = [
21
+ "./translate.spec.js",
22
+ "./currency.spec.js",
23
+ "./current_locale.spec.js",
24
+ "./dates.spec.js",
25
+ "./defaults.spec.js",
26
+ "./interpolation.spec.js",
27
+ "./localization.spec.js",
28
+ "./numbers.spec.js",
29
+ "./placeholder.spec.js",
30
+ "./pluralization.spec.js",
31
+ "./prepare_options.spec.js",
32
+ "./translate.spec.js",
33
+ "./utility_functions.spec.js"
34
+ ];
35
+ var shims = {};
36
+ for(var i = 0; i < testScripts.length; i++) {
37
+ shims[ testScripts[i] ] = {
38
+ "deps": ["i18n"]
39
+ };
40
+ }
41
+ require.config(
42
+ {
43
+ "baseUrl" : "./",
44
+ "paths": {
45
+ "i18n": "../../app/assets/javascripts/i18n"
46
+ },
47
+ /* Since the i18n.js file explicitly names its module 'i18n', but each
48
+ spec uses the full path in the require statement, it appears that
49
+ loading fails. This map will map the full path to the short form.
50
+ */
51
+ "map": {
52
+ "*": {
53
+ "../../app/assets/javascripts/i18n": "i18n"
54
+ }
55
+ },
56
+ "shim": shims
57
+ });
58
+ require((["i18n", './translations']).concat(testScripts),
59
+ function(I18n, translationFactory) {
60
+ // Example for using the translation factory
61
+ I18n.translations = translationFactory();
62
+ console.log(I18n.t('hello'));
63
+
64
+ // Execute the specs
65
+ jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
66
+ jasmine.getEnv().execute();
67
+ });
68
+ </script>
69
+
70
+ </body>
71
+ </html>
@@ -24,6 +24,27 @@ describe("Translate", function(){
24
24
  expect(actual).toEqual(expected);
25
25
  });
26
26
 
27
+ it("returns guessed translation if missingBehaviour is set to guess", function(){
28
+ I18n.missingBehaviour = 'guess'
29
+ actual = I18n.t("invalid.thisIsAutomaticallyGeneratedTranslation");
30
+ expected = 'this is automatically generated translation';
31
+ expect(actual).toEqual(expected);
32
+ });
33
+
34
+ it("returns guessed translation with prefix if missingBehaviour is set to guess and prefix is also provided", function(){
35
+ I18n.missingBehaviour = 'guess'
36
+ I18n.missingTranslationPrefix = 'EE: '
37
+ actual = I18n.t("invalid.thisIsAutomaticallyGeneratedTranslation");
38
+ expected = 'EE: this is automatically generated translation';
39
+ expect(actual).toEqual(expected);
40
+ });
41
+
42
+ it("returns missing message translation for valid scope with scope", function(){
43
+ actual = I18n.t("monster", {scope: "greetings"});
44
+ expected = '[missing "en.greetings.monster" translation]';
45
+ expect(actual).toEqual(expected);
46
+ });
47
+
27
48
  it("returns translation for single scope on a custom locale", function(){
28
49
  I18n.locale = "pt-BR";
29
50
  expect(I18n.t("hello")).toEqual("Olá Mundo!");
@@ -127,7 +127,9 @@ var DEBUG = false;
127
127
  return Translations;
128
128
  };
129
129
 
130
- if (typeof(exports) === "undefined") {
130
+ if (typeof define === 'function' && define.amd) {
131
+ define(function() { return generator; });
132
+ } else if (typeof(exports) === "undefined") {
131
133
  window.Translations = generator;
132
134
  } else {
133
135
  module.exports = generator;
@@ -0,0 +1,71 @@
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(:options) { {namespace: namespace, pretty_print: pretty_print} }
10
+ subject { I18n::JS::Segment.new(file, translations, options) }
11
+
12
+ describe ".new" do
13
+
14
+ it "should persist the file path variable" do
15
+ subject.file.should eql("tmp/i18n-js/segment.js")
16
+ end
17
+
18
+ it "should persist the translations variable" do
19
+ subject.translations.should eql(translations)
20
+ end
21
+
22
+ it "should persist the namespace variable" do
23
+ subject.namespace.should eql("MyNamespace")
24
+ end
25
+
26
+ context "when namespace is nil" do
27
+ let(:namespace){ nil }
28
+
29
+ it "should default namespace to `I18n`" do
30
+ subject.namespace.should eql("I18n")
31
+ end
32
+ end
33
+
34
+ context "when namespace is not set" do
35
+ subject { I18n::JS::Segment.new(file, translations) }
36
+
37
+ it "should default namespace to `I18n`" do
38
+ subject.namespace.should eql("I18n")
39
+ end
40
+ end
41
+
42
+ context "when pretty_print is nil" do
43
+ it "should set pretty_print to false" do
44
+ subject.pretty_print.should be false
45
+ end
46
+ end
47
+
48
+ context "when pretty_print is truthy" do
49
+ let(:pretty_print){ 1 }
50
+
51
+ it "should set pretty_print to true" do
52
+ subject.pretty_print.should be true
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#save!" do
58
+ before { allow(I18n::JS).to receive(:export_i18n_js_dir_path).and_return(temp_path) }
59
+ before { subject.save! }
60
+
61
+ it "should write the file" do
62
+ file_should_exist "segment.js"
63
+
64
+ File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
65
+ MyNamespace.translations || (MyNamespace.translations = {});
66
+ MyNamespace.translations["en"] = {"test":"Test"};
67
+ MyNamespace.translations["fr"] = {"test":"Test2"};
68
+ EOF
69
+ end
70
+ end
71
+ end
@@ -17,7 +17,7 @@ module Helpers
17
17
  end
18
18
 
19
19
  def file_should_exist(name)
20
- file_path = File.join(I18n::JS::DEFAULT_EXPORT_DIR_PATH, name)
20
+ file_path = File.join(temp_path, name)
21
21
  File.should be_file(file_path)
22
22
  end
23
23
 
@@ -0,0 +1,42 @@
1
+
2
+ describe I18n::JS::Dependencies, ".sprockets_supports_register_preprocessor?" do
3
+
4
+ subject { described_class.sprockets_supports_register_preprocessor? }
5
+
6
+ context 'when Sprockets is available to register preprocessors' do
7
+ let!(:sprockets_double) do
8
+ class_double('Sprockets').as_stubbed_const(register_processor: true).tap do |double|
9
+ allow(double).to receive(:respond_to?).with(:register_preprocessor).and_return(true)
10
+ end
11
+ end
12
+
13
+ it { is_expected.to be_truthy }
14
+ it 'calls respond_to? with register_preprocessor on Sprockets' do
15
+ expect(sprockets_double).to receive(:respond_to?).with(:register_preprocessor).and_return(true)
16
+ subject
17
+ end
18
+ end
19
+
20
+ context 'when Sprockets is NOT available to register preprocessors' do
21
+ let!(:sprockets_double) do
22
+ class_double('Sprockets').as_stubbed_const(register_processor: true).tap do |double|
23
+ allow(double).to receive(:respond_to?).with(:register_preprocessor).and_return(false)
24
+ end
25
+ end
26
+
27
+ it { is_expected.to be_falsy }
28
+ it 'calls respond_to? with register_preprocessor on Sprockets' do
29
+ expect(sprockets_double).to receive(:respond_to?).with(:register_preprocessor).and_return(false)
30
+ subject
31
+ end
32
+ end
33
+
34
+ context 'when Sprockets is missing' do
35
+ before do
36
+ hide_const('Sprockets')
37
+ expect { Sprockets }.to raise_error(NameError)
38
+ end
39
+
40
+ it { is_expected.to be_falsy }
41
+ end
42
+ end
@@ -0,0 +1,69 @@
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
+ result[:a].should 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
+ target[:a].should 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
+ result.should 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
+ result.should 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
+ result.should eql({:a => {:c => 2}})
66
+ hash.should eql({:a => {:b => 1, :c => 2}})
67
+ end
68
+ end
69
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc8
4
+ version: 3.0.0.rc9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry-meta
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: gem-release
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +113,7 @@ files:
127
113
  - app/assets/javascripts/i18n/shims.js
128
114
  - app/assets/javascripts/i18n/translations.js
129
115
  - gemfiles/i18n_0_6.gemfile
116
+ - gemfiles/i18n_0_7.gemfile
130
117
  - i18n-js.gemspec
131
118
  - lib/i18n-js.rb
132
119
  - lib/i18n/js.rb
@@ -134,6 +121,7 @@ files:
134
121
  - lib/i18n/js/engine.rb
135
122
  - lib/i18n/js/fallback_locales.rb
136
123
  - lib/i18n/js/middleware.rb
124
+ - lib/i18n/js/segment.rb
137
125
  - lib/i18n/js/utils.rb
138
126
  - lib/i18n/js/version.rb
139
127
  - lib/rails/generators/i18n/js/config/config_generator.rb
@@ -143,12 +131,16 @@ files:
143
131
  - spec/fixtures/custom_path.yml
144
132
  - spec/fixtures/default.yml
145
133
  - spec/fixtures/erb.yml
134
+ - spec/fixtures/except_condition.yml
135
+ - spec/fixtures/js_export_dir_custom.yml
136
+ - spec/fixtures/js_export_dir_none.yml
146
137
  - spec/fixtures/js_file_per_locale.yml
147
138
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml
148
139
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml
149
140
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml
150
141
  - spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml
151
142
  - spec/fixtures/js_file_per_locale_without_fallbacks.yml
143
+ - spec/fixtures/js_file_with_namespace_and_pretty_print.yml
152
144
  - spec/fixtures/locales.yml
153
145
  - spec/fixtures/multiple_conditions.yml
154
146
  - spec/fixtures/multiple_conditions_per_locale.yml
@@ -173,11 +165,16 @@ files:
173
165
  - spec/js/placeholder.spec.js
174
166
  - spec/js/pluralization.spec.js
175
167
  - spec/js/prepare_options.spec.js
168
+ - spec/js/require.js
176
169
  - spec/js/specs.html
170
+ - spec/js/specs_requirejs.html
177
171
  - spec/js/translate.spec.js
178
172
  - spec/js/translations.js
179
173
  - spec/js/utility_functions.spec.js
174
+ - spec/segment_spec.rb
180
175
  - spec/spec_helper.rb
176
+ - spec/sprockets_spec.rb
177
+ - spec/utils_spec.rb
181
178
  homepage: http://rubygems.org/gems/i18n-js
182
179
  licenses:
183
180
  - MIT
@@ -198,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
195
  version: 1.3.1
199
196
  requirements: []
200
197
  rubyforge_project:
201
- rubygems_version: 2.4.3
198
+ rubygems_version: 2.4.6
202
199
  signing_key:
203
200
  specification_version: 4
204
201
  summary: It's a small library to provide the Rails I18n translations on the Javascript.
@@ -206,12 +203,16 @@ test_files:
206
203
  - spec/fixtures/custom_path.yml
207
204
  - spec/fixtures/default.yml
208
205
  - spec/fixtures/erb.yml
206
+ - spec/fixtures/except_condition.yml
207
+ - spec/fixtures/js_export_dir_custom.yml
208
+ - spec/fixtures/js_export_dir_none.yml
209
209
  - spec/fixtures/js_file_per_locale.yml
210
210
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml
211
211
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml
212
212
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml
213
213
  - spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml
214
214
  - spec/fixtures/js_file_per_locale_without_fallbacks.yml
215
+ - spec/fixtures/js_file_with_namespace_and_pretty_print.yml
215
216
  - spec/fixtures/locales.yml
216
217
  - spec/fixtures/multiple_conditions.yml
217
218
  - spec/fixtures/multiple_conditions_per_locale.yml
@@ -236,9 +237,14 @@ test_files:
236
237
  - spec/js/placeholder.spec.js
237
238
  - spec/js/pluralization.spec.js
238
239
  - spec/js/prepare_options.spec.js
240
+ - spec/js/require.js
239
241
  - spec/js/specs.html
242
+ - spec/js/specs_requirejs.html
240
243
  - spec/js/translate.spec.js
241
244
  - spec/js/translations.js
242
245
  - spec/js/utility_functions.spec.js
246
+ - spec/segment_spec.rb
243
247
  - spec/spec_helper.rb
248
+ - spec/sprockets_spec.rb
249
+ - spec/utils_spec.rb
244
250
  has_rdoc: