i18n-js 3.7.1 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/README.md +21 -8
- data/app/assets/javascripts/i18n.js +10 -7
- data/lib/i18n/js/version.rb +1 -1
- data/package.json +1 -1
- data/spec/js/numbers.spec.js +4 -0
- data/spec/js/translate.spec.js +5 -0
- data/spec/js/translations.js +17 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b219edefbe002f4d278f6677a3d1b25a313392e9bcef34f5a6c6ac3ac4a2dd90
|
4
|
+
data.tar.gz: 8aa014849035847f081f9ef53f1824d1405feedb5d2eb61a979885bf3d8b4d06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e75a5ebff4ca0a1572376a816185c42e21ee343b4a44c8b3a4a2c7831241bc5af77a79522b1ce541e86773bce39ae3088365c67fdd8dfe245af522c808ecebaa
|
7
|
+
data.tar.gz: dceaa789df1e2712849300687afcabbbc73a3f4557d2cb3f08bafda30f357ea9b9d794cf914240398cec8798a102f54d9839bdc92d53327e3124715eddcf1c8f
|
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.8.0] - 2020-10-15
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- [JS] Add option `scope` for `toHumanSize()`
|
26
|
+
(PR: https://github.com/fnando/i18n-js/pull/583)
|
27
|
+
|
28
|
+
|
21
29
|
## [3.7.1] - 2020-06-30
|
22
30
|
|
23
31
|
### Fixed
|
@@ -465,7 +473,8 @@ And today is not April Fools' Day
|
|
465
473
|
|
466
474
|
|
467
475
|
|
468
|
-
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.
|
476
|
+
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.8.0...HEAD
|
477
|
+
[3.8.0]: https://github.com/fnando/i18n-js/compare/v3.7.1...v3.8.0
|
469
478
|
[3.7.1]: https://github.com/fnando/i18n-js/compare/v3.7.0...v3.7.1
|
470
479
|
[3.7.0]: https://github.com/fnando/i18n-js/compare/v3.6.0...v3.7.0
|
471
480
|
[3.6.0]: https://github.com/fnando/i18n-js/compare/v3.5.1...v3.6.0
|
data/README.md
CHANGED
@@ -37,6 +37,18 @@ Add the gem to your Gemfile.
|
|
37
37
|
gem "i18n-js"
|
38
38
|
```
|
39
39
|
|
40
|
+
#### Rails with [webpacker](https://github.com/rails/webpacker)
|
41
|
+
|
42
|
+
If you're using `webpacker`, you may need to add the dependencies to your client with:
|
43
|
+
|
44
|
+
```
|
45
|
+
yarn add i18n-js
|
46
|
+
# or, if you're using npm,
|
47
|
+
npm install i18n-js
|
48
|
+
```
|
49
|
+
|
50
|
+
For more details, see [this gist](https://gist.github.com/bazzel/ecdff4718962e57c2d5569cf01d332fe).
|
51
|
+
|
40
52
|
#### Rails app with [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
|
41
53
|
|
42
54
|
If you're using the [asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html),
|
@@ -325,7 +337,7 @@ var i18n = require("i18n-js");
|
|
325
337
|
|
326
338
|
### Setting up
|
327
339
|
|
328
|
-
You **don't** need to set up a thing. The default settings will work just okay. But if you want to split translations into several files or specify
|
340
|
+
You **don't** need to set up a thing. The default settings will work just okay. But if you want to split translations into several files or specify contexts, you can follow the rest of this setting up section.
|
329
341
|
|
330
342
|
Set your locale is easy as
|
331
343
|
```javascript
|
@@ -393,7 +405,7 @@ I18n.t("some.missing.scope", {defaults: [{scope: "some.existing.scope"}]});
|
|
393
405
|
I18n.t("some.missing.scope", {defaults: [{message: "Some message"}]});
|
394
406
|
```
|
395
407
|
|
396
|
-
Default values must be provided as an array of
|
408
|
+
Default values must be provided as an array of hashes where the key is the
|
397
409
|
type of translation desired, a `scope` or a `message`. The translation returned
|
398
410
|
will be either the first scope recognized, or the first message defined.
|
399
411
|
|
@@ -492,7 +504,7 @@ I18n.pluralization["ru"] = function (count) {
|
|
492
504
|
};
|
493
505
|
```
|
494
506
|
|
495
|
-
You can find all rules on <
|
507
|
+
You can find all rules on <https://unicode-org.github.io/cldr-staging/charts/37/supplemental/language_plural_rules.html>.
|
496
508
|
|
497
509
|
If you're using the same scope over and over again, you may use the `scope` option.
|
498
510
|
|
@@ -574,6 +586,7 @@ The `toHumanSize` function accepts the following options:
|
|
574
586
|
- `delimiter`: defaults to `""`
|
575
587
|
- `strip_insignificant_zeros`: defaults to `false`
|
576
588
|
- `format`: defaults to `%n%u`
|
589
|
+
- `scope`: defaults to `""`
|
577
590
|
|
578
591
|
<!---->
|
579
592
|
|
@@ -728,7 +741,7 @@ This method is useful for very large apps where a single contained translations.
|
|
728
741
|
|
729
742
|
To use this with require.js we are only going to change a few things from above.
|
730
743
|
|
731
|
-
1. In your `config/i18n-js.yml` we need to add a better location for the i18n to be exported. You want to use this location so that it can be properly precompiled by r.js.
|
744
|
+
1. In your `config/i18n-js.yml` we need to add a better location for the i18n to be exported to. You want to use this location so that it can be properly precompiled by r.js.
|
732
745
|
|
733
746
|
```yaml
|
734
747
|
export_i18n_js: "app/assets/javascript/nls"
|
@@ -772,7 +785,7 @@ To use this with require.js we are only going to change a few things from above.
|
|
772
785
|
// ...
|
773
786
|
});
|
774
787
|
```
|
775
|
-
4. (optional) As an additional configuration we can make a task to be run before the requirejs optimizer. This will allow any automated scripts that run the requirejs optimizer to export the strings before we run r.js
|
788
|
+
4. (optional) As an additional configuration we can make a task to be run before the requirejs optimizer. This will allow any automated scripts that run the requirejs optimizer to export the strings before we run r.js.
|
776
789
|
|
777
790
|
```rake
|
778
791
|
# lib/tasks/i18n.rake
|
@@ -833,7 +846,7 @@ These commands will remove *all* fingerprinted assets, and you will have to reco
|
|
833
846
|
$ rake assets:precompile
|
834
847
|
```
|
835
848
|
|
836
|
-
or similar commands.
|
849
|
+
or similar commands. If you are precompiling assets on the target machine(s), cached pages may be broken by this, so they will need to be refreshed.
|
837
850
|
|
838
851
|
2. You can change something in a different locale file.
|
839
852
|
|
@@ -844,9 +857,9 @@ or similar commands. If you are precompiling assets on the target machine(s), c
|
|
844
857
|
### Translations in JS are not updated when Sprockets not loaded before this gem
|
845
858
|
|
846
859
|
The "rails engine" declaration will try to detect existence of "sprockets" before adding the initailizer
|
847
|
-
If sprockets is loaded after this gem, the preprocessor for
|
860
|
+
If sprockets is loaded after this gem, the preprocessor for
|
848
861
|
making JS translations file cache to depend on content of locale files will not be hooked.
|
849
|
-
So ensure sprockets is loaded before this gem
|
862
|
+
So ensure sprockets is loaded before this gem by moving the entry of sprockets in the Gemfile or adding "require" statements for sprockets somewhere.
|
850
863
|
|
851
864
|
**Note:** See issue [#404](https://github.com/fnando/i18n-js/issues/404) for more details and discussion of this issue.
|
852
865
|
|
@@ -402,7 +402,7 @@
|
|
402
402
|
|
403
403
|
while (locales.length) {
|
404
404
|
locale = locales.shift();
|
405
|
-
scopes = fullScope.split(this.defaultSeparator);
|
405
|
+
scopes = fullScope.split(options.separator || this.defaultSeparator);
|
406
406
|
translations = this.translations[locale];
|
407
407
|
|
408
408
|
if (!translations) {
|
@@ -459,7 +459,7 @@
|
|
459
459
|
|
460
460
|
while (locales.length) {
|
461
461
|
locale = locales.shift();
|
462
|
-
scopes = scope.split(this.defaultSeparator);
|
462
|
+
scopes = scope.split(options.separator || this.defaultSeparator);
|
463
463
|
translations = this.translations[locale];
|
464
464
|
|
465
465
|
if (!translations) {
|
@@ -685,7 +685,7 @@
|
|
685
685
|
|
686
686
|
var localeForTranslation = (options != null && options.locale != null) ? options.locale : this.currentLocale();
|
687
687
|
var fullScope = this.getFullScope(scope, options);
|
688
|
-
var fullScopeWithLocale = [localeForTranslation, fullScope].join(this.defaultSeparator);
|
688
|
+
var fullScopeWithLocale = [localeForTranslation, fullScope].join(options.separator || this.defaultSeparator);
|
689
689
|
|
690
690
|
return '[missing "' + fullScopeWithLocale + '" translation]';
|
691
691
|
};
|
@@ -1025,6 +1025,7 @@
|
|
1025
1025
|
, iterations = 0
|
1026
1026
|
, unit
|
1027
1027
|
, precision
|
1028
|
+
, fullScope
|
1028
1029
|
;
|
1029
1030
|
|
1030
1031
|
while (size >= kb && iterations < 4) {
|
@@ -1033,10 +1034,12 @@
|
|
1033
1034
|
}
|
1034
1035
|
|
1035
1036
|
if (iterations === 0) {
|
1036
|
-
|
1037
|
+
fullScope = this.getFullScope("number.human.storage_units.units.byte", options);
|
1038
|
+
unit = this.t(fullScope, {count: size});
|
1037
1039
|
precision = 0;
|
1038
1040
|
} else {
|
1039
|
-
|
1041
|
+
fullScope = this.getFullScope("number.human.storage_units.units." + SIZE_UNITS[iterations], options);
|
1042
|
+
unit = this.t(fullScope);
|
1040
1043
|
precision = (size - Math.floor(size) === 0) ? 0 : 1;
|
1041
1044
|
}
|
1042
1045
|
|
@@ -1053,7 +1056,7 @@
|
|
1053
1056
|
|
1054
1057
|
// Deal with the scope as an array.
|
1055
1058
|
if (isArray(scope)) {
|
1056
|
-
scope = scope.join(this.defaultSeparator);
|
1059
|
+
scope = scope.join(options.separator || this.defaultSeparator);
|
1057
1060
|
}
|
1058
1061
|
|
1059
1062
|
// Deal with the scope option provided through the second argument.
|
@@ -1061,7 +1064,7 @@
|
|
1061
1064
|
// I18n.t('hello', {scope: 'greetings'});
|
1062
1065
|
//
|
1063
1066
|
if (options.scope) {
|
1064
|
-
scope = [options.scope, scope].join(this.defaultSeparator);
|
1067
|
+
scope = [options.scope, scope].join(options.separator || this.defaultSeparator);
|
1065
1068
|
}
|
1066
1069
|
|
1067
1070
|
return scope;
|
data/lib/i18n/js/version.rb
CHANGED
data/package.json
CHANGED
data/spec/js/numbers.spec.js
CHANGED
@@ -150,6 +150,10 @@ describe("Numbers", function(){
|
|
150
150
|
expect(I18n.toHumanSize(1024 * 1.6, {precision: 0})).toEqual("2KB");
|
151
151
|
});
|
152
152
|
|
153
|
+
it("returns number as human size using custom scope", function(){
|
154
|
+
expect(I18n.toHumanSize(1024 * 1024, {scope: "extended"})).toEqual("1Megabyte");
|
155
|
+
});
|
156
|
+
|
153
157
|
it("formats numbers with strip insignificant zero", function() {
|
154
158
|
options = {separator: ".", delimiter: ",", strip_insignificant_zeros: true};
|
155
159
|
|
data/spec/js/translate.spec.js
CHANGED
@@ -296,4 +296,9 @@ describe("Translate", function(){
|
|
296
296
|
{foo: "bar"}
|
297
297
|
]);
|
298
298
|
});
|
299
|
+
|
300
|
+
|
301
|
+
it("returns value with key containing dot but different separator specified", function() {
|
302
|
+
expect(I18n.t(["A implies B means something."], {scope: "sentences_with_dots", separator: "|"})).toEqual("A implies B means that when A is true, B must be true.");
|
303
|
+
});
|
299
304
|
});
|
data/spec/js/translations.js
CHANGED
@@ -58,6 +58,18 @@
|
|
58
58
|
}
|
59
59
|
}
|
60
60
|
|
61
|
+
, extended: {
|
62
|
+
number: {
|
63
|
+
human: {
|
64
|
+
storage_units: {
|
65
|
+
units: {
|
66
|
+
"mb": "Megabyte"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
61
73
|
, arrayWithParams: [
|
62
74
|
null,
|
63
75
|
"An item with a param of {{value}}",
|
@@ -67,7 +79,11 @@
|
|
67
79
|
{foo: "bar"}
|
68
80
|
]
|
69
81
|
|
70
|
-
, null_key: null
|
82
|
+
, null_key: null,
|
83
|
+
|
84
|
+
sentences_with_dots: {
|
85
|
+
"A implies B means something.": "A implies B means that when A is true, B must be true."
|
86
|
+
}
|
71
87
|
};
|
72
88
|
|
73
89
|
Translations["en-US"] = {
|
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.8.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: 2020-
|
11
|
+
date: 2020-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|