i18n-js 3.5.1 → 3.7.1

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: 62051e50266fb55f81099456051f21393aba9a4ecabda1bf2739ae181bf64ec6
4
- data.tar.gz: 517cc9090a03e060781be401588b00495a18ccf934fd155ec838d1334b349d7c
3
+ metadata.gz: e8b0336b575e1fcbf19bc557cb7fd709db85f8831a842970c03f34517baa90c2
4
+ data.tar.gz: 4f86f0c6d7e05b0aeb4b8f7898d5947b6a06dd402593d34c068f98da28ed09ff
5
5
  SHA512:
6
- metadata.gz: e88fc0e5f91b673a401310c1b8db1bc5f04a3d3cf5379d978fda9a1030cb5bedb897175577301b5cd4ef86cd025f03c17250c1d5953c7779a48a0911339e7307
7
- data.tar.gz: b7caf39eff008a7817a512f60edffc515a3baa41ff8c7388d54f8fcd59f42e9247ee28567f58c264a319fd9f7049712fc8d0a76a85ca778dad4d70144fb4124f
6
+ metadata.gz: 20f3d107d1e745c7948ff2fa10173712e84bf58894cab7f1d21f58b5c647bf17fb0a664cc2bb4363d3def74898c0a85dda1a8de6c64161400bd1044663a61cc0
7
+ data.tar.gz: bc0fa3a90ff5ef2a23c4f084845238564b6c66d9deb96abb79478f719e37e065744cd775b3d8de33765f1d72a266325672b8bcfe95fc1dbd9c0aceb507538d5c
@@ -12,6 +12,7 @@ rvm:
12
12
  - 2.4
13
13
  - 2.5
14
14
  - 2.6
15
+ - 2.7
15
16
  - ruby-head
16
17
  before_install:
17
18
  # Needed to test JS
@@ -29,6 +30,7 @@ gemfile:
29
30
  - gemfiles/i18n_1_5.gemfile
30
31
  - gemfiles/i18n_1_6.gemfile
31
32
  - gemfiles/i18n_1_7.gemfile
33
+ - gemfiles/i18n_1_8.gemfile
32
34
  matrix:
33
35
  fast_finish: true
34
36
  allow_failures:
data/Appraisals CHANGED
@@ -38,3 +38,7 @@ end
38
38
  appraise "i18n_1_7" do
39
39
  gem "i18n", "~> 1.7.0"
40
40
  end
41
+
42
+ appraise "i18n_1_8" do
43
+ gem "i18n", "~> 1.8.0"
44
+ end
@@ -18,6 +18,30 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [3.7.1] - 2020-06-30
22
+
23
+ ### Fixed
24
+
25
+ - [JS] For translation missing behaviour `guess`, replace all underscores to spaces properly
26
+ (PR: https://github.com/fnando/i18n-js/pull/574)
27
+
28
+
29
+ ## [3.7.0] - 2020-05-29
30
+
31
+ ### Added
32
+
33
+ - [JS] Allow options to be passed in when calling `I18n.localize`/`I18n.l`
34
+ (PR: https://github.com/fnando/i18n-js/pull/570)
35
+
36
+
37
+ ## [3.6.0] - 2020-02-14
38
+
39
+ ### Added
40
+
41
+ - [Ruby] Allow `suffix` to be added to generated translations files
42
+ (PR: https://github.com/fnando/i18n-js/pull/561)
43
+
44
+
21
45
  ## [3.5.1] - 2019-12-21
22
46
 
23
47
  ### Changed
@@ -441,7 +465,10 @@ And today is not April Fools' Day
441
465
 
442
466
 
443
467
 
444
- [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.5.1...HEAD
468
+ [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.7.1...HEAD
469
+ [3.7.1]: https://github.com/fnando/i18n-js/compare/v3.7.0...v3.7.1
470
+ [3.7.0]: https://github.com/fnando/i18n-js/compare/v3.6.0...v3.7.0
471
+ [3.6.0]: https://github.com/fnando/i18n-js/compare/v3.5.1...v3.6.0
445
472
  [3.5.1]: https://github.com/fnando/i18n-js/compare/v3.5.0...v3.5.1
446
473
  [3.5.0]: https://github.com/fnando/i18n-js/compare/v3.4.2...v3.5.0
447
474
  [3.4.2]: https://github.com/fnando/i18n-js/compare/v3.4.1...v3.4.2
data/README.md CHANGED
@@ -248,9 +248,9 @@ MyNamespace.translations["en"] = { ... }
248
248
  ```
249
249
 
250
250
 
251
- ### Adding a line at the beginning of the translations file (useful for imports)
251
+ ### Adding prefix & suffix to the translations file(s)
252
252
 
253
- Setting the `prefix: "import I18n from 'i18n-js';\n"` option will add the line at the beggining of the resultant translation file.
253
+ Setting the `prefix: "import I18n from 'i18n-js';\n"` option will add the line at the beginning of the resultant translation file.
254
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
255
  The user should provide the semi-colon and the newline character if needed.
256
256
 
@@ -267,6 +267,11 @@ will create:
267
267
  ```
268
268
  import I18n from 'i18n-js';
269
269
  I18n.translations || (I18n.translations = {});
270
+ ```
271
+
272
+
273
+ `suffix` option is added in https://github.com/fnando/i18n-js/pull/561.
274
+ It's similar to `prefix` so won't explain it in details.
270
275
 
271
276
 
272
277
  #### Pretty Print
@@ -679,7 +679,7 @@
679
679
  var s = scope.split('.').slice(-1)[0];
680
680
  //replace underscore with space && camelcase with space and lowercase letter
681
681
  return (this.missingTranslationPrefix.length > 0 ? this.missingTranslationPrefix : '') +
682
- s.replace('_',' ').replace(/([a-z])([A-Z])/g,
682
+ s.replace(/_/g,' ').replace(/([a-z])([A-Z])/g,
683
683
  function(match, p1, p2) {return p1 + ' ' + p2.toLowerCase()} );
684
684
  }
685
685
 
@@ -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
 
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "i18n", "~> 1.8.0"
6
+
7
+ gemspec path: "../"
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "i18n", ">= 0.6.6"
22
22
 
23
- s.add_development_dependency "appraisal", "~> 2.0"
23
+ s.add_development_dependency "appraisal", "~> 2.3"
24
24
  s.add_development_dependency "rspec", "~> 3.0"
25
25
  s.add_development_dependency "rake", "~> 12.0"
26
26
  s.add_development_dependency "gem-release", ">= 0.7"
@@ -2,11 +2,12 @@ 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, prefix: nil)
5
+ def initialize(js_extend: false, namespace: nil, pretty_print: false, prefix: nil, suffix: nil)
6
6
  @js_extend = js_extend
7
7
  @namespace = namespace
8
8
  @pretty_print = pretty_print
9
9
  @prefix = prefix
10
+ @suffix = suffix
10
11
  end
11
12
 
12
13
  protected
@@ -9,7 +9,7 @@ module I18n
9
9
  translations.each do |locale, translations_for_locale|
10
10
  contents << line(locale, format_json(translations_for_locale))
11
11
  end
12
- contents
12
+ contents << (@suffix || '')
13
13
  end
14
14
 
15
15
  protected
@@ -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, :prefix, :sort_translation_keys, :json_only].freeze
10
+ OPTIONS = [:namespace, :pretty_print, :js_extend, :prefix, :suffix, :sort_translation_keys, :json_only].freeze
11
11
  LOCALE_INTERPOLATOR = /%\{locale\}/
12
12
 
13
13
  attr_reader *([:file, :translations] | OPTIONS)
@@ -25,6 +25,7 @@ module I18n
25
25
  @pretty_print = !!options[:pretty_print]
26
26
  @js_extend = options.key?(:js_extend) ? !!options[:js_extend] : true
27
27
  @prefix = options.key?(:prefix) ? options[:prefix] : nil
28
+ @suffix = options.key?(:suffix) ? options[:suffix] : nil
28
29
  @sort_translation_keys = options.key?(:sort_translation_keys) ? !!options[:sort_translation_keys] : true
29
30
  @json_only = options.key?(:json_only) ? !!options[:json_only] : false
30
31
  end
@@ -70,7 +71,9 @@ module I18n
70
71
  { js_extend: @js_extend,
71
72
  namespace: @namespace,
72
73
  pretty_print: @pretty_print,
73
- prefix: @prefix }
74
+ prefix: @prefix,
75
+ suffix: @suffix
76
+ }
74
77
  end
75
78
  end
76
79
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module JS
5
- VERSION = "3.5.1"
5
+ VERSION = "3.7.1"
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18n-js",
3
- "version": "3.5.1",
3
+ "version": "3.7.1",
4
4
  "description": "A javascript library similar to Ruby on Rails i18n gem",
5
5
  "author": "Nando Vieira",
6
6
  "license": "MIT",
@@ -6,3 +6,4 @@ translations:
6
6
  namespace: "Foo"
7
7
  pretty_print: true
8
8
  prefix: "import random from 'random-library';\n"
9
+ suffix: "//test"
@@ -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
 
@@ -48,9 +48,14 @@ describe("Translate", function(){
48
48
 
49
49
  it("returns guessed translation if missingBehaviour is set to guess", function(){
50
50
  I18n.missingBehaviour = 'guess'
51
- actual = I18n.translate("invalid.thisIsAutomaticallyGeneratedTranslation");
52
- expected = 'this is automatically generated translation';
53
- expect(actual).toEqual(expected);
51
+
52
+ var actual_1 = I18n.translate("invalid.thisIsAutomaticallyGeneratedTranslation");
53
+ var expected_1 = 'this is automatically generated translation';
54
+ expect(actual_1).toEqual(expected_1);
55
+
56
+ var actual_2 = I18n.translate("invalid.this_is_automatically_generated_translation");
57
+ var expected_2 = 'this is automatically generated translation';
58
+ expect(actual_2).toEqual(expected_2);
54
59
  });
55
60
 
56
61
  it("returns guessed translation with prefix if missingBehaviour is set to guess and prefix is also provided", function(){
@@ -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: ","
@@ -351,7 +351,7 @@ EOS
351
351
  end
352
352
  end
353
353
 
354
- context "namespace, prefix and pretty_print options" do
354
+ context "namespace, prefix, suffix, and pretty_print options" do
355
355
 
356
356
  before do
357
357
  stub_const('I18n::JS::DEFAULT_EXPORT_DIR_PATH', temp_path)
@@ -379,6 +379,7 @@ EOS
379
379
  "foo": "Foo",
380
380
  "fallback_test": "Success"
381
381
  };
382
+ //test
382
383
  EOS
383
384
  }$/)
384
385
  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.5.1
4
+ version: 3.7.1
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: 2019-12-21 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '2.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +126,7 @@ files:
126
126
  - gemfiles/i18n_1_5.gemfile
127
127
  - gemfiles/i18n_1_6.gemfile
128
128
  - gemfiles/i18n_1_7.gemfile
129
+ - gemfiles/i18n_1_8.gemfile
129
130
  - i18n-js.gemspec
130
131
  - lib/i18n-js.rb
131
132
  - lib/i18n/js.rb
@@ -207,7 +208,7 @@ homepage: http://rubygems.org/gems/i18n-js
207
208
  licenses:
208
209
  - MIT
209
210
  metadata: {}
210
- post_install_message:
211
+ post_install_message:
211
212
  rdoc_options: []
212
213
  require_paths:
213
214
  - lib
@@ -222,8 +223,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  - !ruby/object:Gem::Version
223
224
  version: '0'
224
225
  requirements: []
225
- rubygems_version: 3.1.1
226
- signing_key:
226
+ rubygems_version: 3.1.4
227
+ signing_key:
227
228
  specification_version: 4
228
229
  summary: It's a small library to provide the Rails I18n translations on the Javascript.
229
230
  test_files: