i18n-js 3.3.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Appraisals +4 -0
- data/CHANGELOG.md +10 -1
- data/README.md +24 -0
- data/gemfiles/i18n_1_7.gemfile +7 -0
- data/lib/i18n/js/formatters/base.rb +2 -1
- data/lib/i18n/js/formatters/js.rb +2 -1
- data/lib/i18n/js/segment.rb +4 -2
- data/lib/i18n/js/version.rb +1 -1
- data/spec/fixtures/{js_file_with_namespace_and_pretty_print.yml → js_file_with_namespace_prefix_and_pretty_print.yml} +1 -0
- data/spec/ruby/i18n/js_spec.rb +3 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e862238199baf310221642a6913ce7d07b87b2c6934e691bed7bc19a613c09b7
|
4
|
+
data.tar.gz: cdc3db450f6613e82246f2b2ba303ae706bbdaadebee84d34024cd8fb371308c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bc681b8e0b8e7260fd5dfdea56c3733234c8c8afedd0e4c6492ef65356e8b7b6d5ee2e959d5ba26751860c89e237813960e5bc4a45cdb7dbd525fe396277718
|
7
|
+
data.tar.gz: 7aaf234e4f39b7f3eeeff50cadd7f6f8625e235477a83d58bbcf17c30ef7e09ab086de27c85fe5c5f802b6e4f935d81a203abccae80bc65c53a6e549eeb989fb
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
18
18
|
- Nothing
|
19
19
|
|
20
20
|
|
21
|
+
## [3.4.0] - 2019-10-15
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Allow `prefix` to be added to generated translations files
|
26
|
+
(PR: https://github.com/fnando/i18n-js/pull/549)
|
27
|
+
|
28
|
+
|
21
29
|
## [3.3.0] - 2019-06-06
|
22
30
|
|
23
31
|
### Added
|
@@ -400,7 +408,8 @@ And today is not April Fools' Day
|
|
400
408
|
|
401
409
|
|
402
410
|
|
403
|
-
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.
|
411
|
+
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.4.0...HEAD
|
412
|
+
[3.4.0]: https://github.com/fnando/i18n-js/compare/v3.3.0...v3.4.0
|
404
413
|
[3.3.0]: https://github.com/fnando/i18n-js/compare/v3.2.3...v3.3.0
|
405
414
|
[3.2.3]: https://github.com/fnando/i18n-js/compare/v3.2.2...v3.2.3
|
406
415
|
[3.2.2]: https://github.com/fnando/i18n-js/compare/v3.2.1...v3.2.2
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# I18n.js
|
2
2
|
|
3
3
|
[![Gem Version](http://img.shields.io/gem/v/i18n-js.svg?style=flat-square)](http://badge.fury.io/rb/i18n-js)
|
4
|
+
[![npm](https://img.shields.io/npm/v/i18n-js.svg?style=flat-square)](https://www.npmjs.com/package/i18n-js)
|
4
5
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
|
5
6
|
|
6
7
|
[![Build Status](http://img.shields.io/travis/fnando/i18n-js.svg?style=flat-square)](https://travis-ci.org/fnando/i18n-js)
|
@@ -8,6 +9,8 @@
|
|
8
9
|
|
9
10
|
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-1dce73.svg?style=flat-square)](https://gitter.im/fnando/i18n-js)
|
10
11
|
|
12
|
+
> The above badges are generated by https://shields.io/
|
13
|
+
|
11
14
|
It's a small library to provide the Rails I18n translations on the JavaScript.
|
12
15
|
|
13
16
|
Features:
|
@@ -245,6 +248,27 @@ MyNamespace.translations["en"] = { ... }
|
|
245
248
|
```
|
246
249
|
|
247
250
|
|
251
|
+
### Adding a line at the beggining of the translations file (useful for imports)
|
252
|
+
|
253
|
+
Setting the `prefix: "import I18n from 'i18n-js';\n"` option will add the line at the beggining of the resultant translation file.
|
254
|
+
This can be useful to use this gem with the [i18n-js](https://www.npmjs.com/package/i18n-js) npm package, which is quite useful to use it with webpack.
|
255
|
+
The user should provide the semi-colon and the newline character if needed.
|
256
|
+
|
257
|
+
For example:
|
258
|
+
|
259
|
+
```yaml
|
260
|
+
translations:
|
261
|
+
- file: "public/javascripts/i18n/translations.js"
|
262
|
+
prefix: "import I18n from 'i18n-js';\n"
|
263
|
+
```
|
264
|
+
|
265
|
+
will create:
|
266
|
+
|
267
|
+
```
|
268
|
+
import I18n from 'i18n-js';
|
269
|
+
I18n.translations || (I18n.translations = {});
|
270
|
+
|
271
|
+
|
248
272
|
#### Pretty Print
|
249
273
|
|
250
274
|
Set the `pretty_print` option if you would like whitespace and indentation in your output file (default: false)
|
@@ -2,10 +2,11 @@ module I18n
|
|
2
2
|
module JS
|
3
3
|
module Formatters
|
4
4
|
class Base
|
5
|
-
def initialize(js_extend: false, namespace: nil, pretty_print: false)
|
5
|
+
def initialize(js_extend: false, namespace: nil, pretty_print: false, prefix: nil)
|
6
6
|
@js_extend = js_extend
|
7
7
|
@namespace = namespace
|
8
8
|
@pretty_print = pretty_print
|
9
|
+
@prefix = prefix
|
9
10
|
end
|
10
11
|
|
11
12
|
protected
|
@@ -15,7 +15,8 @@ module I18n
|
|
15
15
|
protected
|
16
16
|
|
17
17
|
def header
|
18
|
-
|
18
|
+
text = @prefix || ''
|
19
|
+
text + %(#{@namespace}.translations || (#{@namespace}.translations = {});\n)
|
19
20
|
end
|
20
21
|
|
21
22
|
def line(locale, translations)
|
data/lib/i18n/js/segment.rb
CHANGED
@@ -7,7 +7,7 @@ module I18n
|
|
7
7
|
|
8
8
|
# Class which enscapulates a translations hash and outputs a single JSON translation file
|
9
9
|
class Segment
|
10
|
-
OPTIONS = [:namespace, :pretty_print, :js_extend, :sort_translation_keys, :json_only].freeze
|
10
|
+
OPTIONS = [:namespace, :pretty_print, :js_extend, :prefix, :sort_translation_keys, :json_only].freeze
|
11
11
|
LOCALE_INTERPOLATOR = /%\{locale\}/
|
12
12
|
|
13
13
|
attr_reader *([:file, :translations] | OPTIONS)
|
@@ -24,6 +24,7 @@ module I18n
|
|
24
24
|
@namespace = options[:namespace] || 'I18n'
|
25
25
|
@pretty_print = !!options[:pretty_print]
|
26
26
|
@js_extend = options.key?(:js_extend) ? !!options[:js_extend] : true
|
27
|
+
@prefix = options.key?(:prefix) ? options[:prefix] : nil
|
27
28
|
@sort_translation_keys = options.key?(:sort_translation_keys) ? !!options[:sort_translation_keys] : true
|
28
29
|
@json_only = options.key?(:json_only) ? !!options[:json_only] : false
|
29
30
|
end
|
@@ -68,7 +69,8 @@ module I18n
|
|
68
69
|
def formatter_options
|
69
70
|
{ js_extend: @js_extend,
|
70
71
|
namespace: @namespace,
|
71
|
-
pretty_print: @pretty_print
|
72
|
+
pretty_print: @pretty_print,
|
73
|
+
prefix: @prefix }
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
data/lib/i18n/js/version.rb
CHANGED
data/spec/ruby/i18n/js_spec.rb
CHANGED
@@ -351,11 +351,11 @@ EOS
|
|
351
351
|
end
|
352
352
|
end
|
353
353
|
|
354
|
-
context "namespace and pretty_print options" do
|
354
|
+
context "namespace, prefix and pretty_print options" do
|
355
355
|
|
356
356
|
before do
|
357
357
|
stub_const('I18n::JS::DEFAULT_EXPORT_DIR_PATH', temp_path)
|
358
|
-
set_config "
|
358
|
+
set_config "js_file_with_namespace_prefix_and_pretty_print.yml"
|
359
359
|
end
|
360
360
|
|
361
361
|
it "exports with defined locale as fallback when enabled" do
|
@@ -364,6 +364,7 @@ EOS
|
|
364
364
|
output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "en.js"))
|
365
365
|
expect(output).to match(/^#{
|
366
366
|
<<EOS
|
367
|
+
import random from 'random-library';
|
367
368
|
Foo.translations || (Foo.translations = {});
|
368
369
|
Foo.translations["en"] = {
|
369
370
|
"number": {
|
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.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- gemfiles/i18n_1_4.gemfile
|
126
126
|
- gemfiles/i18n_1_5.gemfile
|
127
127
|
- gemfiles/i18n_1_6.gemfile
|
128
|
+
- gemfiles/i18n_1_7.gemfile
|
128
129
|
- i18n-js.gemspec
|
129
130
|
- lib/i18n-js.rb
|
130
131
|
- lib/i18n/js.rb
|
@@ -158,7 +159,7 @@ files:
|
|
158
159
|
- spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml
|
159
160
|
- spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml
|
160
161
|
- spec/fixtures/js_file_per_locale_without_fallbacks.yml
|
161
|
-
- spec/fixtures/
|
162
|
+
- spec/fixtures/js_file_with_namespace_prefix_and_pretty_print.yml
|
162
163
|
- spec/fixtures/js_sort_translation_keys_false.yml
|
163
164
|
- spec/fixtures/js_sort_translation_keys_true.yml
|
164
165
|
- spec/fixtures/json_only.yml
|
@@ -218,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
219
|
- !ruby/object:Gem::Version
|
219
220
|
version: '0'
|
220
221
|
requirements: []
|
221
|
-
rubygems_version: 3.0.
|
222
|
+
rubygems_version: 3.0.6
|
222
223
|
signing_key:
|
223
224
|
specification_version: 4
|
224
225
|
summary: It's a small library to provide the Rails I18n translations on the Javascript.
|
@@ -238,7 +239,7 @@ test_files:
|
|
238
239
|
- spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml
|
239
240
|
- spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml
|
240
241
|
- spec/fixtures/js_file_per_locale_without_fallbacks.yml
|
241
|
-
- spec/fixtures/
|
242
|
+
- spec/fixtures/js_file_with_namespace_prefix_and_pretty_print.yml
|
242
243
|
- spec/fixtures/js_sort_translation_keys_false.yml
|
243
244
|
- spec/fixtures/js_sort_translation_keys_true.yml
|
244
245
|
- spec/fixtures/json_only.yml
|