i18n-js 3.8.4 → 3.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 228b00c6b2733537cc164228e6da21dfee1531b26186258861b2f710b7c80cae
4
- data.tar.gz: 000d759f9753bb29900a7e09eca044f643cbdde5b0779eeb71683805ac780e14
3
+ metadata.gz: 7d3a003954d81c9cbb7c2f18791ed8baf068f3fbbe6587ce59cd893b7852d1f2
4
+ data.tar.gz: d9fcb2bf3de34987021c2ac556ae65bcecbdfe6cbb638455d6e7919e03268d8c
5
5
  SHA512:
6
- metadata.gz: a180630b6968c7e38723f8d42828e3d9aa6c32d0250e2e28c4a56a644d6a943124bd7183908f5e05616237dc9ebefd69c21a1f0190f2995062745fb12f7b76d9
7
- data.tar.gz: b301cb38ecf02cbf08b92798b0d7457fc00c1903f3fb27ca9c5d821c0c9fdf7f7f500b19b935a1eb3052a066b3057bc763635c4e0e8daf8f7448c500ffc90746
6
+ metadata.gz: 07b6670d05343e82e44041379917a56ee72b185b1bfdcceefe6ae8eae9a1eece1852db7a378eaf8a38f5769ec76587737b200bfb22e50444a02e14bbb4b78793
7
+ data.tar.gz: afe058283a6af31ab843ba2c0da1f1949d37623a3e0823c786cb947b252eac51ffc25c4f856c01e9e1ec87546dd31dddf4705e1f6b5597a3edd02e950e674ed2
data/.editorconfig CHANGED
@@ -1,4 +1,4 @@
1
- # EditorConfig is awesome: http://EditorConfig.org
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
2
 
3
3
  # top-most EditorConfig file
4
4
  root = true
@@ -4,11 +4,13 @@ on:
4
4
  pull_request:
5
5
  branches:
6
6
  - main
7
+ - v3
7
8
  paths-ignore:
8
9
  - 'README.md'
9
10
  push:
10
11
  branches:
11
12
  - main
13
+ - v3
12
14
  paths-ignore:
13
15
  - 'README.md'
14
16
 
@@ -26,6 +28,8 @@ jobs:
26
28
  - 2.5
27
29
  - 2.6
28
30
  - 2.7
31
+ - '3.0'
32
+ - 3.1
29
33
  gemfile:
30
34
  - gemfiles/i18n_0_6.gemfile
31
35
  - gemfiles/i18n_0_7.gemfile
@@ -40,6 +44,8 @@ jobs:
40
44
  - gemfiles/i18n_1_6.gemfile
41
45
  - gemfiles/i18n_1_7.gemfile
42
46
  - gemfiles/i18n_1_8.gemfile
47
+ - gemfiles/i18n_1_9.gemfile
48
+ - gemfiles/i18n_1_10.gemfile
43
49
  allow_failures:
44
50
  - false
45
51
  include:
data/Appraisals CHANGED
@@ -42,3 +42,11 @@ end
42
42
  appraise "i18n_1_8" do
43
43
  gem "i18n", "~> 1.8.0"
44
44
  end
45
+
46
+ appraise "i18n_1_9" do
47
+ gem "i18n", "~> 1.9.0"
48
+ end
49
+
50
+ appraise "i18n_1_10" do
51
+ gem "i18n", "~> 1.10.0"
52
+ end
data/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
- This project adheres to [Semantic Versioning](http://semver.org/).
3
+ This project adheres to [Semantic Versioning](https://semver.org/).
4
4
 
5
5
 
6
6
  ## [Unreleased]
@@ -18,7 +18,31 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
- ## [3.8.4]
21
+ ## [3.9.2] - 2022-03-31
22
+
23
+ ### Fixed
24
+
25
+ - [JS] Fix pluralization fallback in i18n.js
26
+ (PR: https://github.com/fnando/i18n-js/pull/645)
27
+
28
+
29
+ ## [3.9.1] - 2022-02-08
30
+
31
+ ### Changed
32
+
33
+ - [Ruby] Allow rails 7
34
+ (PR: https://github.com/fnando/i18n-js/pull/638)
35
+
36
+
37
+ ## [3.9.0] - 2021-07-30
38
+
39
+ ### Added
40
+
41
+ - [Ruby] Allow to set custom locales instead of using only `I18n.available_locales`.
42
+ (PR: https://github.com/fnando/i18n-js/pull/617)
43
+
44
+
45
+ ## [3.8.4] - 2021-07-27
22
46
 
23
47
  ### Fixed
24
48
 
@@ -26,7 +50,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
26
50
  (PR: https://github.com/fnando/i18n-js/pull/591)
27
51
 
28
52
 
29
- ## [3.8.3]
53
+ ## [3.8.3] - 2021-05-21
30
54
 
31
55
  ### Changed
32
56
 
@@ -509,7 +533,10 @@ And today is not April Fools' Day
509
533
 
510
534
 
511
535
 
512
- [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.8.4...HEAD
536
+ [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.9.2...HEAD
537
+ [3.9.2]: https://github.com/fnando/i18n-js/compare/v3.9.1...v3.9.2
538
+ [3.9.1]: https://github.com/fnando/i18n-js/compare/v3.9.0...v3.9.1
539
+ [3.9.0]: https://github.com/fnando/i18n-js/compare/v3.8.4...v3.9.0
513
540
  [3.8.4]: https://github.com/fnando/i18n-js/compare/v3.8.3...v3.8.4
514
541
  [3.8.3]: https://github.com/fnando/i18n-js/compare/v3.8.2...v3.8.3
515
542
  [3.8.2]: https://github.com/fnando/i18n-js/compare/v3.8.1...v3.8.2
data/README.md CHANGED
@@ -8,11 +8,10 @@
8
8
 
9
9
  <p align="center">
10
10
  <a href="https://github.com/fnando/i18n-js/actions?query=workflow%3ATests"><img src="https://github.com/fnando/i18n-js/workflows/Tests/badge.svg" alt="Tests"></a>
11
- <a href="http://badge.fury.io/rb/i18n-js"><img src="http://img.shields.io/gem/v/i18n-js.svg" alt="Gem Version"></a>
11
+ <a href="https://badge.fury.io/rb/i18n-js"><img src="https://img.shields.io/gem/v/i18n-js.svg" alt="Gem Version"></a>
12
12
  <a href="https://www.npmjs.com/package/i18n-js"><img src="https://img.shields.io/npm/v/i18n-js.svg" alt="npm"></a>
13
13
  <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
14
- <a href="https://travis-ci.org/fnando/i18n-js"><img src="http://img.shields.io/travis/fnando/i18n-js.svg" alt="Build Status"></a>
15
- <a href="https://coveralls.io/r/fnando/i18n-js"><img src="http://img.shields.io/coveralls/fnando/i18n-js.svg" alt="Coverage Status"></a>
14
+ <a href="https://coveralls.io/r/fnando/i18n-js"><img src="https://img.shields.io/coveralls/fnando/i18n-js.svg" alt="Coverage Status"></a>
16
15
  <a href="https://gitter.im/fnando/i18n-js"><img src="https://img.shields.io/badge/gitter-join%20chat-1dce73.svg" alt="Gitter"></a>
17
16
  </p>
18
17
 
@@ -59,10 +58,10 @@ For more details, see:
59
58
  - [this gist](https://gist.github.com/bazzel/ecdff4718962e57c2d5569cf01d332fe)
60
59
  - https://github.com/fnando/i18n-js/issues/597
61
60
 
62
- #### Rails app with [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
61
+ #### Rails app with [Asset Pipeline](https://guides.rubyonrails.org/asset_pipeline.html)
63
62
 
64
63
  If you're using the
65
- [asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html), then you
64
+ [asset pipeline](https://guides.rubyonrails.org/asset_pipeline.html), then you
66
65
  must add the following line to your `app/assets/javascripts/application.js`.
67
66
 
68
67
  ```javascript
@@ -77,7 +76,7 @@ must add the following line to your `app/assets/javascripts/application.js`.
77
76
  //= require i18n/translations
78
77
  ```
79
78
 
80
- #### Rails app without [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
79
+ #### Rails app without [Asset Pipeline](https://guides.rubyonrails.org/asset_pipeline.html)
81
80
 
82
81
  First, put this in your `application.html` (layout file). Then get the JS files
83
82
  following the instructions below.
@@ -271,6 +270,17 @@ You must disable this feature by setting the option to `false`.
271
270
  To find more examples on how to use the configuration file please refer to the
272
271
  tests.
273
272
 
273
+ #### Available locales
274
+
275
+ By specifying option `js_available_locales` with a list of locales, this list
276
+ would be used instead of default `I18n.available_locales` to generate translations.
277
+
278
+ Example:
279
+
280
+ ```yaml
281
+ js_available_locales: ["de", "en"]
282
+ ```
283
+
274
284
  #### Namespace
275
285
 
276
286
  Setting the `namespace` option will change the namespace of the output
@@ -976,23 +986,26 @@ more details and discussion of this issue.
976
986
  ### JS `I18n.toCurrency` & `I18n.toNumber` cannot handle large integers
977
987
 
978
988
  The above methods use `toFixed` and it only supports 53 bit integers. Ref:
979
- http://2ality.com/2012/07/large-integers.html
989
+ https://2ality.com/2012/07/large-integers.html
980
990
 
981
991
  Feel free to find & discuss possible solution(s) at issue
982
992
  [#511](https://github.com/fnando/i18n-js/issues/511)
983
993
 
984
- ### Only works with `Simple` backend
994
+ ### May not work with all backend implementations
985
995
 
986
- If you set `I18n.backend` to something other than the default `Simple` backend,
987
- you will likely get an exception like this:
996
+ I18n backend implementations have to conform to a specific interface to work
997
+ with i18n-js. For backends that do not conform to the interface, you will likely
998
+ get an exception like this:
988
999
 
989
1000
  ```
990
1001
  Undefined method 'initialized?' for <your backend class>
991
1002
  ```
992
1003
 
993
- For now, i18n-js is only compatible with the `Simple` backend. If you need a
994
- more sophisticated backend for your rails application, like
995
- `I18n::Backend::ActiveRecord`, you can setup i18n-js to get translations from a
1004
+ For now, i18n-js is compatible with the `Simple` backend and with
1005
+ `I18n::Backend::ActiveRecord` (>= 0.4.0).
1006
+
1007
+ If you need a more sophisticated backend for your rails application that doesn't
1008
+ implement the required methods, you can setup i18n-js to get translations from a
996
1009
  separate `Simple` backend, by adding the following in an initializer:
997
1010
 
998
1011
  ```ruby
@@ -1031,18 +1044,18 @@ and discussion of this issue.
1031
1044
 
1032
1045
  ## Maintainer
1033
1046
 
1034
- - Nando Vieira - <http://nandovieira.com>
1047
+ - Nando Vieira - <https://nandovieira.com>
1035
1048
 
1036
1049
  ## Contributing
1037
1050
 
1038
1051
  Once you've made your great commits:
1039
1052
 
1040
- 1. [Fork](http://help.github.com/forking/) I18n.js
1053
+ 1. [Fork](https://help.github.com/forking/) I18n.js
1041
1054
  2. Create a branch with a clear name
1042
1055
  3. Make your changes (Please also add/change spec, README and CHANGELOG if
1043
1056
  applicable)
1044
1057
  4. Push changes to the created branch
1045
- 5. [Create an Pull Request](http://github.com/fnando/i18n-js/pulls)
1058
+ 5. [Create an Pull Request](https://github.com/fnando/i18n-js/pulls)
1046
1059
  6. That's it!
1047
1060
 
1048
1061
  Please respect the indentation rules and code style. And use 2 spaces, not tabs.
@@ -33,7 +33,7 @@ if (!Array.prototype.indexOf) {
33
33
  }
34
34
 
35
35
  // Production steps of ECMA-262, Edition 5, 15.4.4.18
36
- // Reference: http://es5.github.com/#x15.4.4.18
36
+ // Reference: https://es5.github.com/#x15.4.4.18
37
37
  // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach
38
38
  if ( !Array.prototype.forEach ) {
39
39
 
@@ -53,7 +53,7 @@ if ( !Array.prototype.forEach ) {
53
53
  var len = O.length >>> 0; // Hack to convert O.length to a UInt32
54
54
 
55
55
  // 4. If IsCallable(callback) is false, throw a TypeError exception.
56
- // See: http://es5.github.com/#x9.11
56
+ // See: https://es5.github.com/#x9.11
57
57
  if ( {}.toString.call(callback) !== "[object Function]" ) {
58
58
  throw new TypeError( callback + " is not a function" );
59
59
  }
@@ -139,7 +139,7 @@ if (!Array.prototype.map) {
139
139
  var len = O.length >>> 0;
140
140
 
141
141
  // 4. If IsCallable(callback) is false, throw a TypeError exception.
142
- // See: http://es5.github.com/#x9.11
142
+ // See: https://es5.github.com/#x9.11
143
143
  if (typeof callback !== 'function') {
144
144
  throw new TypeError(callback + ' is not a function');
145
145
  }
@@ -269,23 +269,23 @@
269
269
  }
270
270
 
271
271
  // Locale code format 1:
272
- // According to RFC4646 (http://www.ietf.org/rfc/rfc4646.txt)
272
+ // According to RFC4646 (https://www.ietf.org/rfc/rfc4646.txt)
273
273
  // language codes for Traditional Chinese should be `zh-Hant`
274
274
  //
275
275
  // But due to backward compatibility
276
276
  // We use older version of IETF language tag
277
- // @see http://www.w3.org/TR/html401/struct/dirlang.html
278
- // @see http://en.wikipedia.org/wiki/IETF_language_tag
277
+ // @see https://www.w3.org/TR/html401/struct/dirlang.html
278
+ // @see https://en.wikipedia.org/wiki/IETF_language_tag
279
279
  //
280
280
  // Format: `language-code = primary-code ( "-" subcode )*`
281
281
  //
282
282
  // primary-code uses ISO639-1
283
- // @see http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
284
- // @see http://www.iso.org/iso/home/standards/language_codes.htm
283
+ // @see https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
284
+ // @see https://www.iso.org/iso/home/standards/language_codes.htm
285
285
  //
286
286
  // subcode uses ISO 3166-1 alpha-2
287
- // @see http://en.wikipedia.org/wiki/ISO_3166
288
- // @see http://www.iso.org/iso/country_codes.htm
287
+ // @see https://en.wikipedia.org/wiki/ISO_3166
288
+ // @see https://www.iso.org/iso/country_codes.htm
289
289
  //
290
290
  // @note
291
291
  // subcode can be in upper case or lower case
@@ -433,7 +433,7 @@
433
433
  , pluralizerKey
434
434
  , message;
435
435
 
436
- if (isObject(translations)) {
436
+ if (translations && isObject(translations)) {
437
437
  while (pluralizerKeys.length) {
438
438
  pluralizerKey = pluralizerKeys.shift();
439
439
  if (isSet(translations[pluralizerKey])) {
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "i18n", "~> 1.10.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "i18n", "~> 1.9.0"
6
+
7
+ gemspec path: "../"
data/i18n-js.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Nando Vieira"]
10
10
  s.email = ["fnando.vieira@gmail.com"]
11
- s.homepage = "http://rubygems.org/gems/i18n-js"
11
+ s.homepage = "https://rubygems.org/gems/i18n-js"
12
12
  s.summary = "It's a small library to provide the Rails I18n translations on the Javascript."
13
13
  s.description = s.summary
14
14
  s.license = "MIT"
@@ -18,7 +18,7 @@ module I18n
18
18
  # Call this in an initializer
19
19
  def using_asset_pipeline?
20
20
  assets_pipeline_available =
21
- (rails3? || rails4? || rails5? || rails6?) &&
21
+ (rails3? || rails4? || rails5? || rails6? || rails7?) &&
22
22
  Rails.respond_to?(:application) &&
23
23
  Rails.application.config.respond_to?(:assets)
24
24
  rails3_assets_enabled =
@@ -26,7 +26,7 @@ module I18n
26
26
  assets_pipeline_available &&
27
27
  Rails.application.config.assets.enabled != false
28
28
 
29
- assets_pipeline_available && (rails4? || rails5? || rails6? || rails3_assets_enabled)
29
+ assets_pipeline_available && (rails4? || rails5? || rails6? || rails7? || rails3_assets_enabled)
30
30
  end
31
31
 
32
32
  private
@@ -46,6 +46,10 @@ module I18n
46
46
  def rails6?
47
47
  rails? && Rails.version.to_i == 6
48
48
  end
49
+
50
+ def rails7?
51
+ rails? && Rails.version.to_i == 7
52
+ end
49
53
 
50
54
  def safe_gem_check(*args)
51
55
  if Gem::Specification.respond_to?(:find_by_name)
@@ -21,7 +21,7 @@ module I18n
21
21
  # https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb
22
22
  #
23
23
  # Finisher hook is the place which should be used as border.
24
- # http://guides.rubyonrails.org/configuring.html#initializers
24
+ # https://guides.rubyonrails.org/configuring.html#initializers
25
25
  #
26
26
  # For detail see Pull Request:
27
27
  # https://github.com/fnando/i18n-js/pull/371
@@ -33,7 +33,7 @@ module I18n
33
33
  # Saves JSON file containing translations
34
34
  def save!
35
35
  if @file =~ LOCALE_INTERPOLATOR
36
- I18n.available_locales.each do |locale|
36
+ I18n::JS.js_available_locales.each do |locale|
37
37
  write_file(file_for_locale(locale), @translations.slice(locale))
38
38
  end
39
39
  else
data/lib/i18n/js/utils.rb CHANGED
@@ -3,7 +3,7 @@ module I18n
3
3
  module Utils
4
4
  PLURAL_KEYS = %i[zero one two few many other].freeze
5
5
 
6
- # Based on deep_merge by Stefan Rusterholz, see <http://www.ruby-forum.com/topic/142809>.
6
+ # Based on deep_merge by Stefan Rusterholz, see <https://www.ruby-forum.com/topic/142809>.
7
7
  # This method is used to handle I18n fallbacks. Given two equivalent path nodes in two locale trees:
8
8
  # 1. If the node in the current locale appears to be an I18n pluralization (:one, :other, etc.),
9
9
  # use the node, but merge in any missing/non-nil keys from the fallback (default) locale.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module JS
5
- VERSION = "3.8.4"
5
+ VERSION = "3.9.2"
6
6
  end
7
7
  end
data/lib/i18n/js.rb CHANGED
@@ -81,7 +81,7 @@ module I18n
81
81
 
82
82
  # deep_merge! given result with result for fallback locale
83
83
  def self.merge_with_fallbacks!(result)
84
- I18n.available_locales.each do |locale|
84
+ js_available_locales.each do |locale|
85
85
  fallback_locales = FallbackLocales.new(fallbacks, locale)
86
86
  fallback_locales.each do |fallback_locale|
87
87
  # `result[fallback_locale]` could be missing
@@ -183,7 +183,7 @@ module I18n
183
183
  #
184
184
  # So the input is wrapped by our class for better `#slice`
185
185
  Private::HashWithSymbolKeys.new(translations).
186
- slice(*::I18n.available_locales).
186
+ slice(*::I18n::JS.js_available_locales).
187
187
  to_h
188
188
  end
189
189
  end
@@ -213,6 +213,16 @@ module I18n
213
213
  end
214
214
  end
215
215
 
216
+ # Get all available locales.
217
+ #
218
+ # @return [Array<Symbol>] the locales.
219
+ def self.js_available_locales
220
+ config.fetch(:js_available_locales) do
221
+ # default value
222
+ I18n.available_locales
223
+ end.map(&:to_sym)
224
+ end
225
+
216
226
  def self.sort_translation_keys?
217
227
  @sort_translation_keys ||= (config[:sort_translation_keys]) if config.key?(:sort_translation_keys)
218
228
  @sort_translation_keys = true if @sort_translation_keys.nil?
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18n-js",
3
- "version": "3.8.0",
3
+ "version": "3.9.2",
4
4
  "description": "A javascript library similar to Ruby on Rails i18n gem",
5
5
  "author": "Nando Vieira",
6
6
  "license": "MIT",
@@ -0,0 +1 @@
1
+ js_available_locales: ["en", "foo"]
@@ -148,6 +148,15 @@ describe("Pluralization", function(){
148
148
  expect(I18n.p(5, "inbox", { count: 5 })).toEqual('You have 5 messages');
149
149
  });
150
150
 
151
+ it("fallback to default locale when I18n.fallbacks is enabled and value is null", function() {
152
+ I18n.locale = "pt-BR";
153
+ I18n.fallbacks = true;
154
+ I18n.translations["pt-BR"].inbox = null;
155
+ expect(I18n.p(0, "inbox", { count: 0 })).toEqual("You have no messages");
156
+ expect(I18n.p(1, "inbox", { count: 1 })).toEqual("You have 1 message");
157
+ expect(I18n.p(5, "inbox", { count: 5 })).toEqual("You have 5 messages");
158
+ });
159
+
151
160
  it("fallback to 'other' scope", function() {
152
161
  I18n.locale = "pt-BR";
153
162
  I18n.fallbacks = true;
data/spec/js/require.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** vim: et:ts=4:sw=4:sts=4
2
2
  * @license RequireJS 2.1.16 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
3
3
  * Available via the MIT or new BSD license.
4
- * see: http://github.com/jrburke/requirejs for details
4
+ * see: https://github.com/jrburke/requirejs for details
5
5
  */
6
6
  //Not using strict: uneven strict support in browsers, #392, and causes
7
7
  //problems with requirejs.exec()/transpiler plugins that may not be strict.
@@ -163,7 +163,7 @@ var requirejs, require, define;
163
163
  * @returns {Error}
164
164
  */
165
165
  function makeError(id, msg, err, requireModules) {
166
- var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
166
+ var e = new Error(msg + '\nhttps://requirejs.org/docs/errors.html#' + id);
167
167
  e.requireType = id;
168
168
  e.requireModules = requireModules;
169
169
  if (err) {
@@ -1810,7 +1810,7 @@ var requirejs, require, define;
1810
1810
  head = s.head = document.getElementsByTagName('head')[0];
1811
1811
  //If BASE tag is in play, using appendChild is a problem for IE6.
1812
1812
  //When that browser dies, this can be removed. Details in this jQuery bug:
1813
- //http://dev.jquery.com/ticket/2709
1813
+ //https://dev.jquery.com/ticket/2709
1814
1814
  baseElement = document.getElementsByTagName('base')[0];
1815
1815
  if (baseElement) {
1816
1816
  head = s.head = baseElement.parentNode;
@@ -1829,7 +1829,7 @@ var requirejs, require, define;
1829
1829
  */
1830
1830
  req.createNode = function (config, moduleName, url) {
1831
1831
  var node = config.xhtml ?
1832
- document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
1832
+ document.createElementNS('https://www.w3.org/1999/xhtml', 'html:script') :
1833
1833
  document.createElement('script');
1834
1834
  node.type = config.scriptType || 'text/javascript';
1835
1835
  node.charset = 'utf-8';
@@ -307,21 +307,30 @@ EOS
307
307
  expect(subject[:de][:null_test]).to eql(nil)
308
308
  end
309
309
 
310
- context "when given locale is in `I18n.available_locales` but its translation is missing" do
310
+ context 'when given locale is in `I18n.available_locales` but its translation is missing' do
311
311
  subject { translations[:fr][:fallback_test] }
312
312
 
313
- let(:new_locale) { :pirate }
314
- let!(:old_available_locales) { I18n.config.available_locales }
315
- let!(:new_available_locales) { I18n.config.available_locales + [new_locale] }
313
+ let(:available_locales) { %i[fr pirate] }
314
+
316
315
  before do
317
- I18n.config.available_locales = new_available_locales
318
- set_config "js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml"
316
+ allow(::I18n).to receive(:available_locales).and_return(available_locales)
317
+ set_config 'js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml'
319
318
  end
320
- after do
321
- I18n.config.available_locales = old_available_locales
319
+
320
+ it { should eql(nil) }
321
+ end
322
+
323
+ context 'when given locale is in `.js_available_locales` but its translation is missing' do
324
+ subject { translations[:fr][:fallback_test] }
325
+
326
+ let(:available_locales) { %i[fr pirate] }
327
+
328
+ before do
329
+ allow(described_class).to receive(:js_available_locales).and_return(available_locales)
330
+ set_config 'js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml'
322
331
  end
323
332
 
324
- it {should eql(nil)}
333
+ it { should eql(nil) }
325
334
  end
326
335
 
327
336
  context "with I18n::Fallbacks enabled" do
@@ -385,27 +394,67 @@ EOS
385
394
  end
386
395
  end
387
396
 
388
- context "I18n.available_locales" do
397
+ describe '.js_available_locales' do
398
+ subject { described_class.js_available_locales }
399
+
400
+ let(:results) { described_class.scoped_translations('*.admin.*.title') }
401
+ let(:result) { ->(locale) { results[locale][:admin][:show][:title] } }
389
402
 
390
- context "when I18n.available_locales is not set" do
391
- it "should allow all locales" do
392
- result = I18n::JS.scoped_translations("*.admin.*.title")
403
+ context 'when I18n.available_locales is not set' do
404
+ it { expect(subject).to eq ::I18n.available_locales }
393
405
 
394
- expect(result[:en][:admin][:show][:title]).to eql("Show")
395
- expect(result[:fr][:admin][:show][:title]).to eql("Visualiser")
396
- expect(result[:ja][:admin][:show][:title]).to eql("Ignore me")
406
+ it 'should allow all locales' do
407
+ expect(result.call(:en)).to eql('Show')
408
+ expect(result.call(:fr)).to eql('Visualiser')
409
+ expect(result.call(:ja)).to eql('Ignore me')
397
410
  end
398
411
  end
399
412
 
400
- context "when I18n.available_locales is set" do
401
- before { allow(::I18n).to receive(:available_locales){ [:en, :fr] } }
413
+ context 'when I18n.available_locales is set' do
414
+ let(:available_locales) { %i[en fr] }
415
+
416
+ before { allow(::I18n).to receive(:available_locales).and_return(available_locales) }
417
+
418
+ it { expect(subject).to eq available_locales }
419
+
420
+ it 'should ignore non-valid locales' do
421
+ expect(result.call(:en)).to eql('Show')
422
+ expect(result.call(:fr)).to eql('Visualiser')
423
+ expect(results).not_to include(:ja)
424
+ end
425
+
426
+ context 'when :js_available_locales set in config' do
427
+ before { set_config 'js_available_locales_custom.yml' }
402
428
 
403
- it "should ignore non-valid locales" do
404
- result = I18n::JS.scoped_translations("*.admin.*.title")
429
+ it { expect(subject).to eq %i[en foo] }
430
+
431
+ it 'should ignore non-valid locales' do
432
+ expect(result.call(:en)).to eql('Show')
433
+ expect(results).not_to include(:fr, :ja)
434
+ end
435
+ end
436
+ end
437
+ end
438
+
439
+ context 'I18n.available_locales' do
440
+ let(:results) { described_class.scoped_translations('*.admin.*.title') }
441
+ let(:result) { ->(locale) { results[locale][:admin][:show][:title] } }
442
+
443
+ context 'when I18n.available_locales is not set' do
444
+ it 'should allow all locales' do
445
+ expect(result.call(:en)).to eql('Show')
446
+ expect(result.call(:fr)).to eql('Visualiser')
447
+ expect(result.call(:ja)).to eql('Ignore me')
448
+ end
449
+ end
450
+
451
+ context 'when I18n.available_locales is set' do
452
+ before { allow(::I18n).to receive(:available_locales){ [:en, :fr] } }
405
453
 
406
- expect(result[:en][:admin][:show][:title]).to eql("Show")
407
- expect(result[:fr][:admin][:show][:title]).to eql("Visualiser")
408
- expect(result.keys.include?(:ja)).to eql(false)
454
+ it 'should ignore non-valid locales' do
455
+ expect(result.call(:en)).to eql('Show')
456
+ expect(result.call(:fr)).to eql('Visualiser')
457
+ expect(results).not_to include(:ja)
409
458
  end
410
459
  end
411
460
  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.8.4
4
+ version: 3.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-27 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -121,6 +121,7 @@ files:
121
121
  - gemfiles/i18n_0_9.gemfile
122
122
  - gemfiles/i18n_1_0.gemfile
123
123
  - gemfiles/i18n_1_1.gemfile
124
+ - gemfiles/i18n_1_10.gemfile
124
125
  - gemfiles/i18n_1_2.gemfile
125
126
  - gemfiles/i18n_1_3.gemfile
126
127
  - gemfiles/i18n_1_4.gemfile
@@ -128,6 +129,7 @@ files:
128
129
  - gemfiles/i18n_1_6.gemfile
129
130
  - gemfiles/i18n_1_7.gemfile
130
131
  - gemfiles/i18n_1_8.gemfile
132
+ - gemfiles/i18n_1_9.gemfile
131
133
  - i18n-js.gemspec
132
134
  - i18njs.png
133
135
  - lib/i18n-js.rb
@@ -152,6 +154,7 @@ files:
152
154
  - spec/fixtures/default.yml
153
155
  - spec/fixtures/erb.yml
154
156
  - spec/fixtures/except_condition.yml
157
+ - spec/fixtures/js_available_locales_custom.yml
155
158
  - spec/fixtures/js_export_dir_custom.yml
156
159
  - spec/fixtures/js_export_dir_none.yml
157
160
  - spec/fixtures/js_extend_parent.yml
@@ -208,11 +211,11 @@ files:
208
211
  - spec/ruby/i18n/js_spec.rb
209
212
  - spec/spec_helper.rb
210
213
  - yarn.lock
211
- homepage: http://rubygems.org/gems/i18n-js
214
+ homepage: https://rubygems.org/gems/i18n-js
212
215
  licenses:
213
216
  - MIT
214
217
  metadata: {}
215
- post_install_message:
218
+ post_install_message:
216
219
  rdoc_options: []
217
220
  require_paths:
218
221
  - lib
@@ -227,8 +230,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
230
  - !ruby/object:Gem::Version
228
231
  version: '0'
229
232
  requirements: []
230
- rubygems_version: 3.2.24
231
- signing_key:
233
+ rubygems_version: 3.3.10
234
+ signing_key:
232
235
  specification_version: 4
233
236
  summary: It's a small library to provide the Rails I18n translations on the Javascript.
234
237
  test_files:
@@ -236,6 +239,7 @@ test_files:
236
239
  - spec/fixtures/default.yml
237
240
  - spec/fixtures/erb.yml
238
241
  - spec/fixtures/except_condition.yml
242
+ - spec/fixtures/js_available_locales_custom.yml
239
243
  - spec/fixtures/js_export_dir_custom.yml
240
244
  - spec/fixtures/js_export_dir_none.yml
241
245
  - spec/fixtures/js_extend_parent.yml