i18n-js 3.0.0.rc12 → 3.0.0.rc13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +20 -1
- data/README.md +19 -1
- data/app/assets/javascripts/i18n.js +12 -1
- data/lib/i18n/js.rb +16 -6
- data/lib/i18n/js/middleware.rb +5 -0
- data/lib/i18n/js/segment.rb +30 -10
- data/lib/i18n/js/version.rb +1 -1
- data/spec/fixtures/js_extend_parent.yml +6 -0
- data/spec/fixtures/js_extend_segment.yml +6 -0
- data/spec/js/dates.spec.js +7 -0
- data/spec/js/translate.spec.js +7 -0
- data/spec/ruby/i18n/js/segment_spec.rb +52 -4
- data/spec/ruby/i18n/js_spec.rb +37 -2
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d618c24aafbe01dfc9573cf7a3df0c214b9b48a
|
4
|
+
data.tar.gz: 22bbc551ae4ba0d927c4d8b61fbf54996f51de4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8ada8c660b2185867aa9c5ed68627aaee251c164032e39cf1b3fd0e9f0690f161defe732055f9eb97945084665208237252174ebf60131e66e6589fdf666506
|
7
|
+
data.tar.gz: aabf496875397c179606adf78bba0bee468e5d923a7d3c6d21d36494b03aab55cc650fdf8a672eea0da410a9c57c18ea07ae7c377129aa275cea6254c260a073
|
data/.travis.yml
CHANGED
@@ -8,6 +8,9 @@ rvm:
|
|
8
8
|
- 2.0
|
9
9
|
- 2.1
|
10
10
|
- 2.2
|
11
|
+
# Since the Travis Build Env does not recognize `2.3` alias yet
|
12
|
+
# We need to specify the version precisely
|
13
|
+
- 2.3.0
|
11
14
|
- ruby-head
|
12
15
|
before_install: # Need to install something extra to test JS
|
13
16
|
- npm install jasmine-node@1.14.2
|
data/CHANGELOG.md
CHANGED
@@ -16,6 +16,24 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
16
16
|
|
17
17
|
- Nothing
|
18
18
|
|
19
|
+
## [3.0.0.rc13] - 2016-06-29
|
20
|
+
|
21
|
+
### Added
|
22
|
+
|
23
|
+
- [Ruby] Added option `js_extend` to not generate JS code for translations with usage of `I18n.extend` ([#397](https://github.com/fnando/i18n-js/pull/397))
|
24
|
+
|
25
|
+
### Changed
|
26
|
+
|
27
|
+
- Nothing
|
28
|
+
|
29
|
+
### Fixed
|
30
|
+
|
31
|
+
- [JS] Initialize option `missingBehaviour` & `missingTranslationPrefix` with default values ([#398](https://github.com/fnando/i18n-js/pull/398))
|
32
|
+
- [JS] Throw an error when `I18n.strftime()` takes an invalid date ([#383](https://github.com/fnando/i18n-js/pull/383))
|
33
|
+
- [JS] Fix default error message when translation missing to consider locale passed in options
|
34
|
+
- [Ruby] Reset middleware cache on rails startup
|
35
|
+
([#402](https://github.com/fnando/i18n-js/pull/402))
|
36
|
+
|
19
37
|
|
20
38
|
## [3.0.0.rc12] - 2015-12-30
|
21
39
|
|
@@ -158,5 +176,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
158
176
|
|
159
177
|
|
160
178
|
|
161
|
-
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.0.0.
|
179
|
+
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.0.0.rc13...HEAD
|
180
|
+
[3.0.0.rc13]: https://github.com/fnando/i18n-js/compare/v3.0.0.rc12...v3.0.0.rc13
|
162
181
|
[3.0.0.rc12]: https://github.com/fnando/i18n-js/compare/v3.0.0.rc11...v3.0.0.rc12
|
data/README.md
CHANGED
@@ -15,6 +15,10 @@ Features:
|
|
15
15
|
- Asset pipeline support
|
16
16
|
- Lots more! :)
|
17
17
|
|
18
|
+
## Version Notice
|
19
|
+
The `master` branch (including this README) is for latest `3.0.0.rc` instead of `2.x`.
|
20
|
+
|
21
|
+
|
18
22
|
## Usage
|
19
23
|
|
20
24
|
### Installation
|
@@ -252,6 +256,20 @@ translations:
|
|
252
256
|
```
|
253
257
|
|
254
258
|
|
259
|
+
#### Javscript Merge (:js_extend option)
|
260
|
+
|
261
|
+
By default, the output file Javascript will call the `I18n.extend` method to ensure that newly loaded locale
|
262
|
+
files are shallow-merged with any locale data already in memory. To disable this either globally or per-file,
|
263
|
+
set the `js_extend` option to false
|
264
|
+
|
265
|
+
```yaml
|
266
|
+
js_extend: false # this will disable Javascript I18n.extend globally
|
267
|
+
translations:
|
268
|
+
- file: "public/javascripts/i18n/translations.js"
|
269
|
+
js_extend: false # this will disable Javascript I18n.extend for this file
|
270
|
+
```
|
271
|
+
|
272
|
+
|
255
273
|
#### Vanilla JavaScript
|
256
274
|
|
257
275
|
Just add the `i18n.js` file to your page. You'll have to build the translations object
|
@@ -262,7 +280,7 @@ by hand or using your favorite programming language. More info below.
|
|
262
280
|
|
263
281
|
Add the following line to your package.json dependencies (where version is the version you want - n.b. npm install requires it to be the gzipped tarball, see [npm install](https://www.npmjs.org/doc/cli/npm-install.html))
|
264
282
|
```javascript
|
265
|
-
"i18n-js": "http://github.com/fnando/i18n-js/archive/v3.0.0.
|
283
|
+
"i18n-js": "http://github.com/fnando/i18n-js/archive/v3.0.0.rc12.tar.gz"
|
266
284
|
```
|
267
285
|
Run npm install then use via
|
268
286
|
```javascript
|
@@ -191,6 +191,12 @@
|
|
191
191
|
|
192
192
|
if (typeof(this.translations) === "undefined" && this.translations !== null)
|
193
193
|
this.translations = DEFAULT_OPTIONS.translations;
|
194
|
+
|
195
|
+
if (typeof(this.missingBehaviour) === "undefined" && this.missingBehaviour !== null)
|
196
|
+
this.missingBehaviour = DEFAULT_OPTIONS.missingBehaviour;
|
197
|
+
|
198
|
+
if (typeof(this.missingTranslationPrefix) === "undefined" && this.missingTranslationPrefix !== null)
|
199
|
+
this.missingTranslationPrefix = DEFAULT_OPTIONS.missingTranslationPrefix;
|
194
200
|
};
|
195
201
|
I18n.initializeOptions();
|
196
202
|
|
@@ -536,8 +542,9 @@
|
|
536
542
|
function(match, p1, p2) {return p1 + ' ' + p2.toLowerCase()} );
|
537
543
|
}
|
538
544
|
|
545
|
+
var localeForTranslation = (options != null && options.locale != null) ? options.locale : this.currentLocale();
|
539
546
|
var fullScope = this.getFullScope(scope, options);
|
540
|
-
var fullScopeWithLocale = [
|
547
|
+
var fullScopeWithLocale = [localeForTranslation, fullScope].join(this.defaultSeparator);
|
541
548
|
|
542
549
|
return '[missing "' + fullScopeWithLocale + '" translation]';
|
543
550
|
};
|
@@ -772,6 +779,10 @@
|
|
772
779
|
|
773
780
|
options = this.prepareOptions(options, DATE);
|
774
781
|
|
782
|
+
if (isNaN(date.getTime())) {
|
783
|
+
throw new Error('I18n.strftime() requires a valid date object, but received an invalid date.');
|
784
|
+
}
|
785
|
+
|
775
786
|
var weekDay = date.getDay()
|
776
787
|
, day = date.getDate()
|
777
788
|
, year = date.getFullYear()
|
data/lib/i18n/js.rb
CHANGED
@@ -48,13 +48,11 @@ module I18n
|
|
48
48
|
only = options[:only] || '*'
|
49
49
|
exceptions = [options[:except] || []].flatten
|
50
50
|
|
51
|
-
segment_options = options.slice(:namespace, :pretty_print)
|
52
|
-
|
53
51
|
result = segment_for_scope(only, exceptions)
|
54
52
|
|
55
53
|
merge_with_fallbacks!(result) if fallbacks
|
56
54
|
|
57
|
-
segments << Segment.new(file, result,
|
55
|
+
segments << Segment.new(file, result, extract_segment_options(options)) unless result.empty?
|
58
56
|
|
59
57
|
segments
|
60
58
|
end
|
@@ -143,7 +141,7 @@ module I18n
|
|
143
141
|
results[scope.to_sym] = tmp unless tmp.nil?
|
144
142
|
end
|
145
143
|
return results
|
146
|
-
elsif translations.respond_to?(:
|
144
|
+
elsif translations.respond_to?(:key?) && translations.key?(scope.to_sym)
|
147
145
|
return {scope.to_sym => scopes.empty? ? translations[scope.to_sym] : filter(translations[scope.to_sym], scopes)}
|
148
146
|
end
|
149
147
|
nil
|
@@ -168,8 +166,15 @@ module I18n
|
|
168
166
|
end
|
169
167
|
end
|
170
168
|
|
169
|
+
def self.js_extend
|
170
|
+
config.fetch(:js_extend) do
|
171
|
+
# default value
|
172
|
+
true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
171
176
|
def self.sort_translation_keys?
|
172
|
-
@sort_translation_keys ||= (config[:sort_translation_keys]) if config.
|
177
|
+
@sort_translation_keys ||= (config[:sort_translation_keys]) if config.key?(:sort_translation_keys)
|
173
178
|
@sort_translation_keys = true if @sort_translation_keys.nil?
|
174
179
|
@sort_translation_keys
|
175
180
|
end
|
@@ -178,6 +183,11 @@ module I18n
|
|
178
183
|
@sort_translation_keys = !!value
|
179
184
|
end
|
180
185
|
|
186
|
+
def self.extract_segment_options(options)
|
187
|
+
segment_options = {js_extend: js_extend, sort_translation_keys: sort_translation_keys?}.with_indifferent_access
|
188
|
+
segment_options.merge(options.slice(*Segment::OPTIONS))
|
189
|
+
end
|
190
|
+
|
181
191
|
### Export i18n.js
|
182
192
|
begin
|
183
193
|
|
@@ -192,7 +202,7 @@ module I18n
|
|
192
202
|
end
|
193
203
|
|
194
204
|
def self.export_i18n_js_dir_path
|
195
|
-
@export_i18n_js_dir_path ||= (config[:export_i18n_js] || :none) if config.
|
205
|
+
@export_i18n_js_dir_path ||= (config[:export_i18n_js] || :none) if config.key?(:export_i18n_js)
|
196
206
|
@export_i18n_js_dir_path ||= DEFAULT_EXPORT_DIR_PATH
|
197
207
|
@export_i18n_js_dir_path
|
198
208
|
end
|
data/lib/i18n/js/middleware.rb
CHANGED
@@ -3,6 +3,7 @@ module I18n
|
|
3
3
|
class Middleware
|
4
4
|
def initialize(app)
|
5
5
|
@app = app
|
6
|
+
clear_cache
|
6
7
|
end
|
7
8
|
|
8
9
|
def call(env)
|
@@ -30,6 +31,10 @@ module I18n
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
def clear_cache
|
35
|
+
File.delete(cache_path) if File.exist?(cache_path)
|
36
|
+
end
|
37
|
+
|
33
38
|
def save_cache(new_cache)
|
34
39
|
# path could be a symbolic link
|
35
40
|
FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
|
data/lib/i18n/js/segment.rb
CHANGED
@@ -3,22 +3,25 @@ module I18n
|
|
3
3
|
|
4
4
|
# Class which enscapulates a translations hash and outputs a single JSON translation file
|
5
5
|
class Segment
|
6
|
-
|
7
|
-
|
6
|
+
OPTIONS = [:namespace, :pretty_print, :js_extend, :sort_translation_keys].freeze
|
8
7
|
LOCALE_INTERPOLATOR = /%\{locale\}/
|
9
8
|
|
9
|
+
attr_reader *([:file, :translations] | OPTIONS)
|
10
|
+
|
10
11
|
def initialize(file, translations, options = {})
|
11
12
|
@file = file
|
12
13
|
@translations = translations
|
13
14
|
@namespace = options[:namespace] || 'I18n'
|
14
15
|
@pretty_print = !!options[:pretty_print]
|
16
|
+
@js_extend = options.key?(:js_extend) ? !!options[:js_extend] : true
|
17
|
+
@sort_translation_keys = options.key?(:sort_translation_keys) ? !!options[:sort_translation_keys] : true
|
15
18
|
end
|
16
19
|
|
17
20
|
# Saves JSON file containing translations
|
18
21
|
def save!
|
19
|
-
if
|
22
|
+
if @file =~ LOCALE_INTERPOLATOR
|
20
23
|
I18n.available_locales.each do |locale|
|
21
|
-
write_file(file_for_locale(locale),
|
24
|
+
write_file(file_for_locale(locale), @translations.slice(locale))
|
22
25
|
end
|
23
26
|
else
|
24
27
|
write_file
|
@@ -27,20 +30,37 @@ module I18n
|
|
27
30
|
|
28
31
|
protected
|
29
32
|
|
30
|
-
def write_file(_file =
|
33
|
+
def write_file(_file = @file, _translations = @translations)
|
31
34
|
FileUtils.mkdir_p File.dirname(_file)
|
32
35
|
File.open(_file, "w+") do |f|
|
33
|
-
f <<
|
36
|
+
f << js_header
|
34
37
|
_translations.each do |locale, translations_for_locale|
|
35
|
-
|
36
|
-
f << %(#{self.namespace}.translations["#{locale}"] = I18n.extend((#{self.namespace}.translations["#{locale}"] || {}), #{print_json(output_translations)});\n)
|
38
|
+
f << js_translations(locale, translations_for_locale)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
def js_header
|
44
|
+
%(#{@namespace}.translations || (#{@namespace}.translations = {});\n)
|
45
|
+
end
|
46
|
+
|
47
|
+
def js_translations(locale, translations)
|
48
|
+
translations = Utils.deep_key_sort(translations) if @sort_translation_keys
|
49
|
+
translations = print_json(translations)
|
50
|
+
js_translations_line(locale, translations)
|
51
|
+
end
|
52
|
+
|
53
|
+
def js_translations_line(locale, translations)
|
54
|
+
if @js_extend
|
55
|
+
%(#{@namespace}.translations["#{locale}"] = I18n.extend((#{@namespace}.translations["#{locale}"] || {}), #{translations});\n)
|
56
|
+
else
|
57
|
+
%(#{@namespace}.translations["#{locale}"] = #{translations};\n)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
41
61
|
# Outputs pretty or ugly JSON depending on :pretty_print option
|
42
62
|
def print_json(translations)
|
43
|
-
if pretty_print
|
63
|
+
if @pretty_print
|
44
64
|
JSON.pretty_generate(translations)
|
45
65
|
else
|
46
66
|
translations.to_json
|
@@ -49,7 +69,7 @@ module I18n
|
|
49
69
|
|
50
70
|
# interpolates filename
|
51
71
|
def file_for_locale(locale)
|
52
|
-
|
72
|
+
@file.gsub(LOCALE_INTERPOLATOR, locale.to_s)
|
53
73
|
end
|
54
74
|
end
|
55
75
|
end
|
data/lib/i18n/js/version.rb
CHANGED
data/spec/js/dates.spec.js
CHANGED
@@ -255,4 +255,11 @@ describe("Dates", function(){
|
|
255
255
|
date = new Date(2009, 3, 26, 7, 35, 44);
|
256
256
|
expect(I18n.strftime(date, "%p")).toEqual("de:AM");
|
257
257
|
});
|
258
|
+
|
259
|
+
it("fails to format invalid date", function(){
|
260
|
+
var date = new Date('foo');
|
261
|
+
expect(function() {
|
262
|
+
I18n.strftime(date, "%a");
|
263
|
+
}).toThrow('I18n.strftime() requires a valid date object, but received an invalid date.');
|
264
|
+
});
|
258
265
|
});
|
data/spec/js/translate.spec.js
CHANGED
@@ -24,6 +24,12 @@ describe("Translate", function(){
|
|
24
24
|
expect(actual).toEqual(expected);
|
25
25
|
});
|
26
26
|
|
27
|
+
it("returns missing message translation with provided locale for invalid scope", function(){
|
28
|
+
actual = I18n.t("invalid.scope", { locale: "ja" });
|
29
|
+
expected = '[missing "ja.invalid.scope" translation]';
|
30
|
+
expect(actual).toEqual(expected);
|
31
|
+
});
|
32
|
+
|
27
33
|
it("returns guessed translation if missingBehaviour is set to guess", function(){
|
28
34
|
I18n.missingBehaviour = 'guess'
|
29
35
|
actual = I18n.t("invalid.thisIsAutomaticallyGeneratedTranslation");
|
@@ -180,6 +186,7 @@ describe("Translate", function(){
|
|
180
186
|
it("escapes $ when doing substitution (IE)", function(){
|
181
187
|
I18n.locale = "en";
|
182
188
|
|
189
|
+
expect(I18n.t("paid", {price: "$0"})).toEqual("You were paid $0");
|
183
190
|
expect(I18n.t("paid", {price: "$0.12"})).toEqual("You were paid $0.12");
|
184
191
|
expect(I18n.t("paid", {price: "$1.35"})).toEqual("You were paid $1.35");
|
185
192
|
});
|
@@ -6,7 +6,12 @@ describe I18n::JS::Segment do
|
|
6
6
|
let(:translations){ { en: { "test" => "Test" }, fr: { "test" => "Test2" } } }
|
7
7
|
let(:namespace) { "MyNamespace" }
|
8
8
|
let(:pretty_print){ nil }
|
9
|
-
let(:
|
9
|
+
let(:js_extend) { nil }
|
10
|
+
let(:sort_translation_keys){ nil }
|
11
|
+
let(:options) { { namespace: namespace,
|
12
|
+
pretty_print: pretty_print,
|
13
|
+
js_extend: js_extend,
|
14
|
+
sort_translation_keys: sort_translation_keys }.delete_if{|k,v| v.nil?} }
|
10
15
|
subject { I18n::JS::Segment.new(file, translations, options) }
|
11
16
|
|
12
17
|
describe ".new" do
|
@@ -89,10 +94,38 @@ MyNamespace.translations["fr"] = I18n.extend((MyNamespace.translations["fr"] ||
|
|
89
94
|
end
|
90
95
|
end
|
91
96
|
|
92
|
-
context "when
|
93
|
-
|
94
|
-
|
97
|
+
context "when js_extend is true" do
|
98
|
+
let(:js_extend){ true }
|
99
|
+
|
100
|
+
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
101
|
+
|
102
|
+
it 'should output the keys as sorted' do
|
103
|
+
file_should_exist "segment.js"
|
104
|
+
|
105
|
+
File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
|
106
|
+
MyNamespace.translations || (MyNamespace.translations = {});
|
107
|
+
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"a":"Test","b":"Test"});
|
108
|
+
EOF
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when js_extend is false" do
|
113
|
+
let(:js_extend){ false }
|
114
|
+
|
115
|
+
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
116
|
+
|
117
|
+
it 'should output the keys as sorted' do
|
118
|
+
file_should_exist "segment.js"
|
119
|
+
|
120
|
+
File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
|
121
|
+
MyNamespace.translations || (MyNamespace.translations = {});
|
122
|
+
MyNamespace.translations["en"] = {"a":"Test","b":"Test"};
|
123
|
+
EOF
|
95
124
|
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when sort_translation_keys is true" do
|
128
|
+
let(:sort_translation_keys){ true }
|
96
129
|
|
97
130
|
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
98
131
|
|
@@ -105,5 +138,20 @@ MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] ||
|
|
105
138
|
EOF
|
106
139
|
end
|
107
140
|
end
|
141
|
+
|
142
|
+
context "when sort_translation_keys is false" do
|
143
|
+
let(:sort_translation_keys){ false }
|
144
|
+
|
145
|
+
let(:translations){ { en: { "b" => "Test", "a" => "Test" } } }
|
146
|
+
|
147
|
+
it 'should output the keys as sorted' do
|
148
|
+
file_should_exist "segment.js"
|
149
|
+
|
150
|
+
File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
|
151
|
+
MyNamespace.translations || (MyNamespace.translations = {});
|
152
|
+
MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"b":"Test","a":"Test"});
|
153
|
+
EOF
|
154
|
+
end
|
155
|
+
end
|
108
156
|
end
|
109
157
|
end
|
data/spec/ruby/i18n/js_spec.rb
CHANGED
@@ -30,14 +30,14 @@ describe I18n::JS do
|
|
30
30
|
|
31
31
|
it "exports messages using custom output path" do
|
32
32
|
set_config "custom_path.yml"
|
33
|
-
I18n::JS::Segment.should_receive(:new).with("tmp/i18n-js/all.js", translations, {}).and_call_original
|
33
|
+
I18n::JS::Segment.should_receive(:new).with("tmp/i18n-js/all.js", translations, {js_extend: true, sort_translation_keys: true}).and_call_original
|
34
34
|
I18n::JS::Segment.any_instance.should_receive(:save!).with(no_args)
|
35
35
|
I18n::JS.export
|
36
36
|
end
|
37
37
|
|
38
38
|
it "sets default scope to * when not specified" do
|
39
39
|
set_config "no_scope.yml"
|
40
|
-
I18n::JS::Segment.should_receive(:new).with("tmp/i18n-js/no_scope.js", translations, {}).and_call_original
|
40
|
+
I18n::JS::Segment.should_receive(:new).with("tmp/i18n-js/no_scope.js", translations, {js_extend: true, sort_translation_keys: true}).and_call_original
|
41
41
|
I18n::JS::Segment.any_instance.should_receive(:save!).with(no_args)
|
42
42
|
I18n::JS.export
|
43
43
|
end
|
@@ -587,6 +587,41 @@ EOS
|
|
587
587
|
end
|
588
588
|
end
|
589
589
|
end
|
590
|
+
end
|
591
|
+
|
592
|
+
describe "js_extend option" do
|
593
|
+
before do
|
594
|
+
stub_const('I18n::JS::DEFAULT_EXPORT_DIR_PATH', temp_path)
|
595
|
+
end
|
596
|
+
|
597
|
+
it "exports with js_extend option at parent level" do
|
598
|
+
set_config "js_extend_parent.yml"
|
599
|
+
I18n::JS.export
|
600
|
+
|
601
|
+
file_should_exist "js_extend_parent.js"
|
602
|
+
|
603
|
+
output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "js_extend_parent.js"))
|
604
|
+
expect(output).to eq(<<EOS
|
605
|
+
I18n.translations || (I18n.translations = {});
|
606
|
+
I18n.translations[\"en\"] = {\"date\":{\"formats\":{\"default\":\"%Y-%m-%d\",\"long\":\"%B %d, %Y\",\"short\":\"%b %d\"}}};
|
607
|
+
I18n.translations[\"fr\"] = {\"date\":{\"formats\":{\"default\":\"%d/%m/%Y\",\"long\":\"%e %B %Y\",\"long_ordinal\":\"%e %B %Y\",\"only_day\":\"%e\",\"short\":\"%e %b\"}}};
|
608
|
+
EOS
|
609
|
+
)
|
610
|
+
end
|
611
|
+
|
612
|
+
it "exports with js_extend option at segment level" do
|
613
|
+
set_config "js_extend_segment.yml"
|
614
|
+
I18n::JS.export
|
590
615
|
|
616
|
+
file_should_exist "js_extend_segment.js"
|
617
|
+
|
618
|
+
output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "js_extend_segment.js"))
|
619
|
+
expect(output).to eq(<<EOS
|
620
|
+
I18n.translations || (I18n.translations = {});
|
621
|
+
I18n.translations[\"en\"] = {\"date\":{\"formats\":{\"default\":\"%Y-%m-%d\",\"long\":\"%B %d, %Y\",\"short\":\"%b %d\"}}};
|
622
|
+
I18n.translations[\"fr\"] = {\"date\":{\"formats\":{\"default\":\"%d/%m/%Y\",\"long\":\"%e %B %Y\",\"long_ordinal\":\"%e %B %Y\",\"only_day\":\"%e\",\"short\":\"%e %b\"}}};
|
623
|
+
EOS
|
624
|
+
)
|
625
|
+
end
|
591
626
|
end
|
592
627
|
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.
|
4
|
+
version: 3.0.0.rc13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -140,6 +140,8 @@ files:
|
|
140
140
|
- spec/fixtures/except_condition.yml
|
141
141
|
- spec/fixtures/js_export_dir_custom.yml
|
142
142
|
- spec/fixtures/js_export_dir_none.yml
|
143
|
+
- spec/fixtures/js_extend_parent.yml
|
144
|
+
- spec/fixtures/js_extend_segment.yml
|
143
145
|
- spec/fixtures/js_file_per_locale.yml
|
144
146
|
- spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml
|
145
147
|
- spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml
|
@@ -206,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
208
|
version: 1.3.1
|
207
209
|
requirements: []
|
208
210
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.
|
211
|
+
rubygems_version: 2.6.4
|
210
212
|
signing_key:
|
211
213
|
specification_version: 4
|
212
214
|
summary: It's a small library to provide the Rails I18n translations on the Javascript.
|
@@ -217,6 +219,8 @@ test_files:
|
|
217
219
|
- spec/fixtures/except_condition.yml
|
218
220
|
- spec/fixtures/js_export_dir_custom.yml
|
219
221
|
- spec/fixtures/js_export_dir_none.yml
|
222
|
+
- spec/fixtures/js_extend_parent.yml
|
223
|
+
- spec/fixtures/js_extend_segment.yml
|
220
224
|
- spec/fixtures/js_file_per_locale.yml
|
221
225
|
- spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml
|
222
226
|
- spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml
|