i18n-js 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29ffee5ef86025eb985994d60c97d8cd88d915993faa3c5016ee441151dd5d2c
4
- data.tar.gz: 208ed897a249121db4fabb69344f362afbe716888f5f8e7a7fae0857fc5f3764
3
+ metadata.gz: dbf33a6af551aff2ea13db6c39e84c568f426aaaacd78b1a27524917a05cc580
4
+ data.tar.gz: a7ba15b0084e0eed0eb8a9f3692131c8786401a3ed257217d0d6ba43cdefd3d3
5
5
  SHA512:
6
- metadata.gz: 3f3c3cf2649ae0d92fb9eb641c500a198f4228842f96e39948a9aaddcef01f8a5c2cd1967f83b6f2a7d70766d59f95c82da91a20bcecccc2ccd8c0a5ff1f19db
7
- data.tar.gz: fa583dcd0070426fec841dc5a699837703ec3fa511fa1155e5d154909e733aba915cc6caf7543166652eab26ac64dfe7a9329d42e46238f784bc9ed18f144660
6
+ metadata.gz: f5bb0487ef02b35454d86e92c9d1634cee3ac9eaa302fcc19044e22c80491682fe4e5c44eef2d6aa90ff91ff0f15db4f2bd7539b4de8e66773be54ba880b193d
7
+ data.tar.gz: f6d56fb7550b4cce0d02e25cf98b38be75cfc3d0cb9cfe3ac0ba050621a08363b7ff49abc4ddc5803d8ac3be3f864bbb3187bb3476e18e91479484f8accd0622
@@ -18,6 +18,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [3.7.0] - 2020-05-29
22
+
23
+ ### Added
24
+
25
+ - [JS] Allow options to be passed in when calling `I18n.localize`/`I18n.l`
26
+ (PR: https://github.com/fnando/i18n-js/pull/570)
27
+
28
+
21
29
  ## [3.6.0] - 2020-02-14
22
30
 
23
31
  ### Added
@@ -449,7 +457,8 @@ And today is not April Fools' Day
449
457
 
450
458
 
451
459
 
452
- [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.6.0...HEAD
460
+ [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.7.0...HEAD
461
+ [3.6.0]: https://github.com/fnando/i18n-js/compare/v3.6.0...v3.7.0
453
462
  [3.6.0]: https://github.com/fnando/i18n-js/compare/v3.5.1...v3.6.0
454
463
  [3.5.1]: https://github.com/fnando/i18n-js/compare/v3.5.0...v3.5.1
455
464
  [3.5.0]: https://github.com/fnando/i18n-js/compare/v3.4.2...v3.5.0
@@ -779,8 +779,8 @@
779
779
  I18n.toCurrency = function(number, options) {
780
780
  options = this.prepareOptions(
781
781
  options
782
- , this.lookup("number.currency.format")
783
- , this.lookup("number.format")
782
+ , this.lookup("number.currency.format", options)
783
+ , this.lookup("number.format", options)
784
784
  , CURRENCY_FORMAT
785
785
  );
786
786
 
@@ -799,17 +799,17 @@
799
799
 
800
800
  switch (scope) {
801
801
  case "currency":
802
- return this.toCurrency(value);
802
+ return this.toCurrency(value, options);
803
803
  case "number":
804
- scope = this.lookup("number.format");
804
+ scope = this.lookup("number.format", options);
805
805
  return this.toNumber(value, scope);
806
806
  case "percentage":
807
- return this.toPercentage(value);
807
+ return this.toPercentage(value, options);
808
808
  default:
809
809
  var localizedValue;
810
810
 
811
811
  if (scope.match(/^(date|time)/)) {
812
- localizedValue = this.toTime(scope, value);
812
+ localizedValue = this.toTime(scope, value, options);
813
813
  } else {
814
814
  localizedValue = value.toString();
815
815
  }
@@ -914,8 +914,8 @@
914
914
  // %Y - Year with century
915
915
  // %z/%Z - Timezone offset (+0545)
916
916
  //
917
- I18n.strftime = function(date, format) {
918
- var options = this.lookup("date")
917
+ I18n.strftime = function(date, format, options) {
918
+ var options = this.lookup("date", options)
919
919
  , meridianOptions = I18n.meridian()
920
920
  ;
921
921
 
@@ -984,9 +984,9 @@
984
984
  };
985
985
 
986
986
  // Convert the given dateString into a formatted date.
987
- I18n.toTime = function(scope, dateString) {
987
+ I18n.toTime = function(scope, dateString, options) {
988
988
  var date = this.parseDate(dateString)
989
- , format = this.lookup(scope)
989
+ , format = this.lookup(scope, options)
990
990
  ;
991
991
 
992
992
  // A date input of `null` or `undefined` will be returned as-is
@@ -1003,15 +1003,15 @@
1003
1003
  return date_string;
1004
1004
  }
1005
1005
 
1006
- return this.strftime(date, format);
1006
+ return this.strftime(date, format, options);
1007
1007
  };
1008
1008
 
1009
1009
  // Convert a number into a formatted percentage value.
1010
1010
  I18n.toPercentage = function(number, options) {
1011
1011
  options = this.prepareOptions(
1012
1012
  options
1013
- , this.lookup("number.percentage.format")
1014
- , this.lookup("number.format")
1013
+ , this.lookup("number.percentage.format", options)
1014
+ , this.lookup("number.format", options)
1015
1015
  , PERCENTAGE_FORMAT
1016
1016
  );
1017
1017
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module JS
5
- VERSION = "3.6.0"
5
+ VERSION = "3.7.0"
6
6
  end
7
7
  end
@@ -36,6 +36,20 @@ describe("Localization", function(){
36
36
  expect(I18n.localize("date.formats.long", "2009-01-07")).toEqual("07 de Janeiro de 2009");
37
37
  });
38
38
 
39
+ it("localizes strings with locale from options", function(){
40
+ I18n.locale = "en";
41
+
42
+ expect(I18n.localize("date.formats.default", "2009-11-29", { locale: "pt-BR" })).toEqual("29/11/2009");
43
+ expect(I18n.localize("date.formats.short", "2009-01-07", { locale: "pt-BR" })).toEqual("07 de Janeiro");
44
+ expect(I18n.localize("date.formats.long", "2009-01-07", { locale: "pt-BR" })).toEqual("07 de Janeiro de 2009");
45
+ expect(I18n.localize("time.formats.default", "2009-11-29 15:07:59", { locale: "pt-BR" })).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
46
+ expect(I18n.localize("time.formats.short", "2009-01-07 09:12:35", { locale: "pt-BR" })).toEqual("07/01, 09:12 h");
47
+ expect(I18n.localize("time.formats.long", "2009-11-29 15:07:59", { locale: "pt-BR" })).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
48
+ expect(I18n.localize("number", 1234567, { locale: "pt-BR" })).toEqual("1,234,567.000");
49
+ expect(I18n.localize("currency", 1234567, { locale: "pt-BR" })).toEqual("R$ 1.234.567,00");
50
+ expect(I18n.localize("percentage", 123.45, { locale: "pt-BR" })).toEqual("123,45%");
51
+ });
52
+
39
53
  it("localizes time strings", function(){
40
54
  I18n.locale = "pt-BR";
41
55
 
@@ -90,7 +90,16 @@
90
90
  hello: "Olá Mundo!"
91
91
 
92
92
  , number: {
93
- percentage: {
93
+ currency: {
94
+ format: {
95
+ delimiter: ".",
96
+ format: "%u %n",
97
+ precision: 2,
98
+ separator: ",",
99
+ unit: "R$"
100
+ }
101
+ }
102
+ , percentage: {
94
103
  format: {
95
104
  delimiter: ""
96
105
  , separator: ","
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.6.0
4
+ version: 3.7.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-02-14 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  - !ruby/object:Gem::Version
224
224
  version: '0'
225
225
  requirements: []
226
- rubygems_version: 3.1.1
226
+ rubygems_version: 3.1.3
227
227
  signing_key:
228
228
  specification_version: 4
229
229
  summary: It's a small library to provide the Rails I18n translations on the Javascript.