i18n-js 3.0.0.rc11 → 3.0.0.rc12

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,6 +38,47 @@
38
38
  return ("0" + number.toString()).substr(-2);
39
39
  };
40
40
 
41
+ // Improved toFixed number rounding function with support for unprecise floating points
42
+ // JavaScript's standard toFixed function does not round certain numbers correctly (for example 0.105 with precision 2).
43
+ var toFixed = function(number, precision) {
44
+ return decimalAdjust('round', number, -precision).toFixed(precision);
45
+ };
46
+
47
+ // Is a given variable an object?
48
+ // Borrowed from Underscore.js
49
+ var isObject = function(obj) {
50
+ var type = typeof obj;
51
+ return type === 'function' || type === 'object' && !!obj;
52
+ };
53
+
54
+ // Is a given value an array?
55
+ // Borrowed from Underscore.js
56
+ var isArray = function(obj) {
57
+ if (Array.isArray) {
58
+ return Array.isArray(obj);
59
+ };
60
+ return Object.prototype.toString.call(obj) === '[object Array]';
61
+ };
62
+
63
+ var decimalAdjust = function(type, value, exp) {
64
+ // If the exp is undefined or zero...
65
+ if (typeof exp === 'undefined' || +exp === 0) {
66
+ return Math[type](value);
67
+ }
68
+ value = +value;
69
+ exp = +exp;
70
+ // If the value is not a number or the exp is not an integer...
71
+ if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
72
+ return NaN;
73
+ }
74
+ // Shift
75
+ value = value.toString().split('e');
76
+ value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
77
+ // Shift back
78
+ value = value.toString().split('e');
79
+ return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
80
+ }
81
+
41
82
  // Set default days/months translations.
42
83
  var DATE = {
43
84
  day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
@@ -86,7 +127,7 @@
86
127
  , locale: "en"
87
128
  // Set the translation key separator.
88
129
  , defaultSeparator: "."
89
- // Set the placeholder format. Accepts `{placeholder}}` and `%{placeholder}`.}
130
+ // Set the placeholder format. Accepts `{{placeholder}}` and `%{placeholder}`.
90
131
  , placeholder: /(?:\{\{|%\{)(.*?)(?:\}\}?)/gm
91
132
  // Set if engine should fallback to the default locale when a translation
92
133
  // is missing.
@@ -179,7 +220,7 @@
179
220
  result = result(locale);
180
221
  }
181
222
 
182
- if (result instanceof Array === false) {
223
+ if (isArray(result) === false) {
183
224
  result = [result];
184
225
  }
185
226
 
@@ -408,7 +449,7 @@
408
449
 
409
450
  if (typeof(translation) === "string") {
410
451
  translation = this.interpolate(translation, options);
411
- } else if (translation instanceof Object && this.isSet(options.count)) {
452
+ } else if (isObject(translation) && this.isSet(options.count)) {
412
453
  translation = this.pluralize(options.count, translation, options);
413
454
  }
414
455
 
@@ -438,9 +479,9 @@
438
479
  if (this.isSet(options[name])) {
439
480
  value = options[name].toString().replace(/\$/gm, "_#$#_");
440
481
  } else if (name in options) {
441
- value = this.nullPlaceholder(placeholder, message);
482
+ value = this.nullPlaceholder(placeholder, message, options);
442
483
  } else {
443
- value = this.missingPlaceholder(placeholder, message);
484
+ value = this.missingPlaceholder(placeholder, message, options);
444
485
  }
445
486
 
446
487
  regex = new RegExp(placeholder.replace(/\{/gm, "\\{").replace(/\}/gm, "\\}"));
@@ -457,7 +498,7 @@
457
498
  options = this.prepareOptions(options);
458
499
  var translations, pluralizer, keys, key, message;
459
500
 
460
- if (scope instanceof Object) {
501
+ if (isObject(scope)) {
461
502
  translations = scope;
462
503
  } else {
463
504
  translations = this.lookup(scope, options);
@@ -502,7 +543,7 @@
502
543
  };
503
544
 
504
545
  // Return a missing placeholder message for given parameters
505
- I18n.missingPlaceholder = function(placeholder, message) {
546
+ I18n.missingPlaceholder = function(placeholder, message, options) {
506
547
  return "[missing " + placeholder + " value]";
507
548
  };
508
549
 
@@ -529,7 +570,7 @@
529
570
  );
530
571
 
531
572
  var negative = number < 0
532
- , string = Math.abs(number).toFixed(options.precision).toString()
573
+ , string = toFixed(Math.abs(number), options.precision).toString()
533
574
  , parts = string.split(".")
534
575
  , precision
535
576
  , buffer = []
@@ -857,7 +898,32 @@
857
898
  }
858
899
 
859
900
  return scope;
860
- }
901
+ };
902
+ /**
903
+ * Merge obj1 with obj2 (shallow merge), without modifying inputs
904
+ * @param {Object} obj1
905
+ * @param {Object} obj2
906
+ * @returns {Object} Merged values of obj1 and obj2
907
+ *
908
+ * In order to support ES3, `Object.prototype.hasOwnProperty.call` is used
909
+ * Idea is from:
910
+ * https://stackoverflow.com/questions/8157700/object-has-no-hasownproperty-method-i-e-its-undefined-ie8
911
+ */
912
+ I18n.extend = function ( obj1, obj2 ) {
913
+ var extended = {};
914
+ var prop;
915
+ for (prop in obj1) {
916
+ if (Object.prototype.hasOwnProperty.call(obj1, prop)) {
917
+ extended[prop] = obj1[prop];
918
+ }
919
+ }
920
+ for (prop in obj2) {
921
+ if (Object.prototype.hasOwnProperty.call(obj2, prop)) {
922
+ extended[prop] = obj2[prop];
923
+ }
924
+ }
925
+ return extended;
926
+ };
861
927
 
862
928
  // Set aliases, so we can save some typing.
863
929
  I18n.t = I18n.translate;
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "i18n", "0.6.11"
5
+ gem "i18n", "~> 0.6.0", ">= 0.6.6"
6
6
 
7
7
  gemspec :path => "../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "i18n", "0.7.0"
5
+ gem "i18n", "~> 0.7.0"
6
6
 
7
7
  gemspec :path => "../"
data/i18n-js.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency "i18n", "~> 0.6"
21
+ s.add_dependency "i18n", "~> 0.6", ">= 0.6.6"
22
22
  s.add_development_dependency "appraisal", "~> 2.0"
23
23
  s.add_development_dependency "activesupport", ">= 3.2.22"
24
24
  s.add_development_dependency "rspec", "~> 3.0"
@@ -3,15 +3,36 @@ require "i18n/js"
3
3
  module I18n
4
4
  module JS
5
5
  class Engine < ::Rails::Engine
6
- initializer "i18n-js.register_preprocessor", :after => "sprockets.environment" do
6
+ # `sprockets.environment` was used for 1.x of `sprockets-rails`
7
+ # https://github.com/rails/sprockets-rails/issues/227
8
+ #
9
+ # References for current values:
10
+ #
11
+ # Here is where sprockets are attached with Rails. There is no 'sprockets.environment' mentioned.
12
+ # https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb
13
+ #
14
+ # Finisher hook is the place which should be used as border.
15
+ # http://guides.rubyonrails.org/configuring.html#initializers
16
+ #
17
+ # For detail see Pull Request:
18
+ # https://github.com/fnando/i18n-js/pull/371
19
+ initializer "i18n-js.register_preprocessor", after: :engines_blank_point, before: :finisher_hook do
7
20
  next unless JS::Dependencies.using_asset_pipeline?
8
21
  next unless JS::Dependencies.sprockets_supports_register_preprocessor?
9
22
 
10
- Rails.application.assets.register_preprocessor "application/javascript", :"i18n-js_dependencies" do |context, source|
11
- if context.logical_path == "i18n/filtered"
12
- ::I18n.load_path.each {|path| context.depend_on(File.expand_path(path))}
23
+ # From README of 2.x & 3.x of `sprockets-rails`
24
+ # It seems the `configure` block is preferred way to call `register_preprocessor`
25
+ # Not sure if this will break older versions of rails
26
+ #
27
+ # https://github.com/rails/sprockets-rails/blob/v2.3.3/README.md
28
+ # https://github.com/rails/sprockets-rails/blob/v3.0.0/README.md
29
+ Rails.application.config.assets.configure do |config|
30
+ config.register_preprocessor "application/javascript", :"i18n-js_dependencies" do |context, source|
31
+ if context.logical_path == "i18n/filtered"
32
+ ::I18n.load_path.each {|path| context.depend_on(File.expand_path(path))}
33
+ end
34
+ source
13
35
  end
14
- source
15
36
  end
16
37
  end
17
38
  end
@@ -73,7 +73,7 @@ module I18n
73
73
  # This ignores option `I18n.enforce_available_locales`
74
74
  def ensure_valid_locales!(locales)
75
75
  if locales.any? { |locale| !::I18n.available_locales.include?(locale) }
76
- fail ArgumentError, "Valid locales: #{::I18n.available_locales} - Given Locales: #{locales}"
76
+ fail ArgumentError, "Valid locales: #{::I18n.available_locales.join(", ")} - Given Locales: #{locales.join(", ")}"
77
77
  end
78
78
  end
79
79
  end
@@ -33,7 +33,7 @@ module I18n
33
33
  f << %(#{self.namespace}.translations || (#{self.namespace}.translations = {});\n)
34
34
  _translations.each do |locale, translations_for_locale|
35
35
  output_translations = I18n::JS.sort_translation_keys? ? Utils.deep_key_sort(translations_for_locale) : translations_for_locale
36
- f << %(#{self.namespace}.translations["#{locale}"] = #{print_json(output_translations)};\n);
36
+ f << %(#{self.namespace}.translations["#{locale}"] = I18n.extend((#{self.namespace}.translations["#{locale}"] || {}), #{print_json(output_translations)});\n)
37
37
  end
38
38
  end
39
39
  end
@@ -4,7 +4,7 @@ module I18n
4
4
  MAJOR = 3
5
5
  MINOR = 0
6
6
  PATCH = 0
7
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.rc11"
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.rc12"
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,41 @@
1
+ var I18n = require("../../app/assets/javascripts/i18n")
2
+ , Translations = require("./translations")
3
+ ;
4
+
5
+ describe("Extend", function () {
6
+ it("should return an object", function () {
7
+ expect(typeof I18n.extend()).toBe('object');
8
+ });
9
+
10
+ it("should merge 2 objects into 1", function () {
11
+ var obj1 = {
12
+ test1: "abc"
13
+ }
14
+ , obj2 = {
15
+ test2: "xyz"
16
+ }
17
+ , expected = {
18
+ test1: "abc"
19
+ , test2: "xyz"
20
+ };
21
+
22
+ expect(I18n.extend(obj1,obj2)).toEqual(expected);
23
+ });
24
+ it("should overwrite a property from obj1 with the same property of obj2", function () {
25
+ var obj1 = {
26
+ test1: "abc"
27
+ , test3: "def"
28
+ }
29
+ , obj2 = {
30
+ test2: "xyz"
31
+ , test3: "uvw"
32
+ }
33
+ , expected = {
34
+ test1: "abc"
35
+ , test2: "xyz"
36
+ , test3: "uvw"
37
+ };
38
+
39
+ expect(I18n.extend(obj1,obj2)).toEqual(expected);
40
+ });
41
+ });
@@ -97,4 +97,17 @@ describe("Interpolation", function(){
97
97
  expect(actual).toEqual("Hello !");
98
98
  I18n.nullPlaceholder = orig;
99
99
  });
100
+
101
+ it("provides missingPlaceholder with the placeholder, message, and options object", function(){
102
+ var orig = I18n.missingPlaceholder;
103
+ I18n.missingPlaceholder = function(placeholder, message, options) {
104
+ expect(placeholder).toEqual('{{name}}');
105
+ expect(message).toEqual('Hello {{name}}!');
106
+ expect(options.debugScope).toEqual('landing-page');
107
+ return '[missing-placeholder-debug]';
108
+ };
109
+ actual = I18n.t("greetings.name", {debugScope: 'landing-page'});
110
+ expect(actual).toEqual("Hello [missing-placeholder-debug]!");
111
+ I18n.missingPlaceholder = orig;
112
+ });
100
113
  });
@@ -0,0 +1,31 @@
1
+ var I18n = require("../../app/assets/javascripts/i18n");
2
+
3
+ describe("Locales", function(){
4
+ beforeEach(function(){
5
+ I18n.reset();
6
+ });
7
+
8
+ it("returns the requested locale, if available", function(){
9
+ I18n.locales["ab"] = ["ab"];
10
+ expect(I18n.locales.get("ab")).toEqual(["ab"]);
11
+ });
12
+
13
+ it("wraps single results in an array", function(){
14
+ I18n.locales["cd"] = "cd";
15
+ expect(I18n.locales.get("cd")).toEqual(["cd"]);
16
+ });
17
+
18
+ it("returns the result of locale functions", function(){
19
+ I18n.locales["fn"] = function() {
20
+ return "gg";
21
+ };
22
+ expect(I18n.locales.get("fn")).toEqual(["gg"]);
23
+ });
24
+
25
+ it("uses I18n.locale as a fallback", function(){
26
+ I18n.locale = "xx";
27
+ I18n.locales["xx"] = ["xx"];
28
+ expect(I18n.locales.get()).toEqual(["xx"]);
29
+ expect(I18n.locales.get("yy")).toEqual(["xx"]);
30
+ });
31
+ });
@@ -97,6 +97,34 @@ describe("Numbers", function(){
97
97
  expect(I18n.toNumber(1.98, options)).toEqual("2");
98
98
  });
99
99
 
100
+ it("rounds numbers correctly when precision is given", function(){
101
+ options = {separator: ".", delimiter: ","};
102
+
103
+ options["precision"] = 2;
104
+ expect(I18n.toNumber(0.104, options)).toEqual("0.10");
105
+
106
+ options["precision"] = 2;
107
+ expect(I18n.toNumber(0.105, options)).toEqual("0.11");
108
+
109
+ options["precision"] = 2;
110
+ expect(I18n.toNumber(1.005, options)).toEqual("1.01");
111
+
112
+ options["precision"] = 3;
113
+ expect(I18n.toNumber(35.855, options)).toEqual("35.855");
114
+
115
+ options["precision"] = 2;
116
+ expect(I18n.toNumber(35.855, options)).toEqual("35.86");
117
+
118
+ options["precision"] = 1;
119
+ expect(I18n.toNumber(35.855, options)).toEqual("35.9");
120
+
121
+ options["precision"] = 0;
122
+ expect(I18n.toNumber(35.855, options)).toEqual("36");
123
+
124
+ options["precision"] = 0;
125
+ expect(I18n.toNumber(0.000000000000001, options)).toEqual("0");
126
+ });
127
+
100
128
  it("returns number as human size", function(){
101
129
  var kb = 1024;
102
130
 
@@ -139,4 +167,4 @@ describe("Numbers", function(){
139
167
  actual = I18n.toNumber(30, {strip_insignificant_zeros: true, precision: 0});
140
168
  expect(actual).toEqual("30");
141
169
  });
142
- });
170
+ });
data/spec/js/specs.html CHANGED
@@ -31,12 +31,14 @@
31
31
  <script type="text/javascript" src="defaults.spec.js"></script>
32
32
  <script type="text/javascript" src="interpolation.spec.js"></script>
33
33
  <script type="text/javascript" src="localization.spec.js"></script>
34
+ <script type="text/javascript" src="locales.spec.js"></script>
34
35
  <script type="text/javascript" src="numbers.spec.js"></script>
35
36
  <script type="text/javascript" src="placeholder.spec.js"></script>
36
37
  <script type="text/javascript" src="pluralization.spec.js"></script>
37
38
  <script type="text/javascript" src="prepare_options.spec.js"></script>
38
39
  <script type="text/javascript" src="translate.spec.js"></script>
39
40
  <script type="text/javascript" src="utility_functions.spec.js"></script>
41
+ <script type="text/javascript" src="extend.spec.js"></script>
40
42
 
41
43
  <!-- run specs -->
42
44
  <script type="text/javascript">
@@ -13,7 +13,7 @@
13
13
 
14
14
  <!-- load your javascript files -->
15
15
  <script type="text/javascript" src="require.js"></script>
16
-
16
+
17
17
  <script type="text/javascript">
18
18
  // Prepare requirejs shims to wrap each test so that it will work with the
19
19
  // require syntax loading
@@ -30,7 +30,8 @@
30
30
  "./pluralization.spec.js",
31
31
  "./prepare_options.spec.js",
32
32
  "./translate.spec.js",
33
- "./utility_functions.spec.js"
33
+ "./utility_functions.spec.js",
34
+ "./extend.spec.js"
34
35
  ];
35
36
  var shims = {};
36
37
  for(var i = 0; i < testScripts.length; i++) {
@@ -103,7 +103,7 @@ describe("Translate", function(){
103
103
  expect(I18n.t("hello")).toEqual("Hei Verden!");
104
104
  });
105
105
 
106
- describe("when provided default valutes", function() {
106
+ describe("when provided default values", function() {
107
107
  it("uses scope provided in defaults if scope doesn't exist", function() {
108
108
  actual = I18n.t("Hello!", {defaults: [{scope: "greetings.stranger"}]});
109
109
  expect(actual).toEqual("Hello stranger!");
@@ -1,3 +1,4 @@
1
+ require "spec_helper"
1
2
 
2
3
  describe I18n::JS::Dependencies, ".sprockets_supports_register_preprocessor?" do
3
4
 
@@ -64,8 +64,8 @@ describe I18n::JS::Segment do
64
64
 
65
65
  File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
66
66
  MyNamespace.translations || (MyNamespace.translations = {});
67
- MyNamespace.translations["en"] = {"test":"Test"};
68
- MyNamespace.translations["fr"] = {"test":"Test2"};
67
+ MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"test":"Test"});
68
+ MyNamespace.translations["fr"] = I18n.extend((MyNamespace.translations["fr"] || {}), {"test":"Test2"});
69
69
  EOF
70
70
  end
71
71
  end
@@ -79,12 +79,12 @@ MyNamespace.translations["fr"] = {"test":"Test2"};
79
79
 
80
80
  File.open(File.join(temp_path, "en.js")){|f| f.read}.should eql <<-EOF
81
81
  MyNamespace.translations || (MyNamespace.translations = {});
82
- MyNamespace.translations["en"] = {"test":"Test"};
82
+ MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"test":"Test"});
83
83
  EOF
84
84
 
85
85
  File.open(File.join(temp_path, "fr.js")){|f| f.read}.should eql <<-EOF
86
86
  MyNamespace.translations || (MyNamespace.translations = {});
87
- MyNamespace.translations["fr"] = {"test":"Test2"};
87
+ MyNamespace.translations["fr"] = I18n.extend((MyNamespace.translations["fr"] || {}), {"test":"Test2"});
88
88
  EOF
89
89
  end
90
90
  end
@@ -101,7 +101,7 @@ MyNamespace.translations["fr"] = {"test":"Test2"};
101
101
 
102
102
  File.open(File.join(temp_path, "segment.js")){|f| f.read}.should eql <<-EOF
103
103
  MyNamespace.translations || (MyNamespace.translations = {});
104
- MyNamespace.translations["en"] = {"a":"Test","b":"Test"};
104
+ MyNamespace.translations["en"] = I18n.extend((MyNamespace.translations["en"] || {}), {"a":"Test","b":"Test"});
105
105
  EOF
106
106
  end
107
107
  end
File without changes
@@ -67,13 +67,13 @@ describe I18n::JS do
67
67
  en_output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "en.js"))
68
68
  expect(en_output).to eq(<<EOS
69
69
  I18n.translations || (I18n.translations = {});
70
- I18n.translations["en"] = {"admin":{"edit":{"title":"Edit"},"show":{"note":"more details","title":"Show"}},"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"]}};
70
+ I18n.translations["en"] = I18n.extend((I18n.translations["en"] || {}), {"admin":{"edit":{"title":"Edit"},"show":{"note":"more details","title":"Show"}},"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"]}});
71
71
  EOS
72
72
  )
73
73
  fr_output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "fr.js"))
74
74
  expect(fr_output).to eq(<<EOS
75
75
  I18n.translations || (I18n.translations = {});
76
- I18n.translations["fr"] = {"admin":{"edit":{"title":"Editer"},"show":{"note":"plus de détails","title":"Visualiser"}},"date":{"abbr_day_names":["dim","lun","mar","mer","jeu","ven","sam"],"abbr_month_names":[null,"jan.","fév.","mar.","avr.","mai","juin","juil.","août","sept.","oct.","nov.","déc."],"day_names":["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],"formats":{"default":"%d/%m/%Y","long":"%e %B %Y","long_ordinal":"%e %B %Y","only_day":"%e","short":"%e %b"},"month_names":[null,"janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"]}};
76
+ I18n.translations["fr"] = I18n.extend((I18n.translations["fr"] || {}), {"admin":{"edit":{"title":"Editer"},"show":{"note":"plus de détails","title":"Visualiser"}},"date":{"abbr_day_names":["dim","lun","mar","mer","jeu","ven","sam"],"abbr_month_names":[null,"jan.","fév.","mar.","avr.","mai","juin","juil.","août","sept.","oct.","nov.","déc."],"day_names":["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],"formats":{"default":"%d/%m/%Y","long":"%e %B %Y","long_ordinal":"%e %B %Y","only_day":"%e","short":"%e %b"},"month_names":[null,"janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"]}});
77
77
  EOS
78
78
  )
79
79
  end
@@ -98,13 +98,13 @@ EOS
98
98
  en_output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "bits.en.js"))
99
99
  expect(en_output).to eq(<<EOS
100
100
  I18n.translations || (I18n.translations = {});
101
- I18n.translations["en"] = {"date":{"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"}},"number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}}}};
101
+ I18n.translations["en"] = I18n.extend((I18n.translations["en"] || {}), {"date":{"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"}},"number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}}}});
102
102
  EOS
103
103
  )
104
104
  fr_output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "bits.fr.js"))
105
105
  expect(fr_output).to eq(<<EOS
106
106
  I18n.translations || (I18n.translations = {});
107
- I18n.translations["fr"] = {"date":{"formats":{"default":"%d/%m/%Y","long":"%e %B %Y","long_ordinal":"%e %B %Y","only_day":"%e","short":"%e %b"}},"number":{"currency":{"format":{"format":"%n %u","precision":2,"unit":"€"}}}};
107
+ I18n.translations["fr"] = I18n.extend((I18n.translations["fr"] || {}), {"date":{"formats":{"default":"%d/%m/%Y","long":"%e %B %Y","long_ordinal":"%e %B %Y","only_day":"%e","short":"%e %b"}},"number":{"currency":{"format":{"format":"%n %u","precision":2,"unit":"€"}}}});
108
108
  EOS
109
109
  )
110
110
  end
@@ -581,7 +581,7 @@ EOS
581
581
  it "exports with the keys sorted" do
582
582
  expect(subject).to eq(<<EOS
583
583
  I18n.translations || (I18n.translations = {});
584
- I18n.translations["en"] = {"admin":{"edit":{"title":"Edit"},"show":{"note":"more details","title":"Show"}},"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"]},"fallback_test":"Success","foo":"Foo","null_test":"fallback for null","number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}},"format":{"delimiter":",","precision":3,"separator":"."}},"time":{"am":"am","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","long":"%B %d, %Y %H:%M","short":"%d %b %H:%M"},"pm":"pm"}};
584
+ I18n.translations["en"] = I18n.extend((I18n.translations["en"] || {}), {"admin":{"edit":{"title":"Edit"},"show":{"note":"more details","title":"Show"}},"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"]},"fallback_test":"Success","foo":"Foo","null_test":"fallback for null","number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}},"format":{"delimiter":",","precision":3,"separator":"."}},"time":{"am":"am","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","long":"%B %d, %Y %H:%M","short":"%d %b %H:%M"},"pm":"pm"}});
585
585
  EOS
586
586
  )
587
587
  end
data/spec/spec_helper.rb CHANGED
@@ -18,7 +18,7 @@ module Helpers
18
18
 
19
19
  def file_should_exist(name)
20
20
  file_path = File.join(temp_path, name)
21
- File.should be_file(file_path)
21
+ expect(File.file?(file_path)).to eq(true)
22
22
  end
23
23
 
24
24
  def temp_path(file_name = "")
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.0.0.rc11
4
+ version: 3.0.0.rc12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2015-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.6.6
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.6.6
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: appraisal
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -151,18 +157,18 @@ files:
151
157
  - spec/fixtures/no_config.yml
152
158
  - spec/fixtures/no_scope.yml
153
159
  - spec/fixtures/simple_scope.yml
154
- - spec/i18n_js_fallback_locales_spec.rb
155
- - spec/i18n_js_spec.rb
156
160
  - spec/js/currency.spec.js
157
161
  - spec/js/current_locale.spec.js
158
162
  - spec/js/dates.spec.js
159
163
  - spec/js/defaults.spec.js
164
+ - spec/js/extend.spec.js
160
165
  - spec/js/interpolation.spec.js
161
166
  - spec/js/jasmine/MIT.LICENSE
162
167
  - spec/js/jasmine/jasmine-html.js
163
168
  - spec/js/jasmine/jasmine.css
164
169
  - spec/js/jasmine/jasmine.js
165
170
  - spec/js/jasmine/jasmine_favicon.png
171
+ - spec/js/locales.spec.js
166
172
  - spec/js/localization.spec.js
167
173
  - spec/js/numbers.spec.js
168
174
  - spec/js/placeholder.spec.js
@@ -174,10 +180,12 @@ files:
174
180
  - spec/js/translate.spec.js
175
181
  - spec/js/translations.js
176
182
  - spec/js/utility_functions.spec.js
177
- - spec/segment_spec.rb
183
+ - spec/ruby/i18n/js/dependencies_spec.rb
184
+ - spec/ruby/i18n/js/fallback_locales_spec.rb
185
+ - spec/ruby/i18n/js/segment_spec.rb
186
+ - spec/ruby/i18n/js/utils_spec.rb
187
+ - spec/ruby/i18n/js_spec.rb
178
188
  - spec/spec_helper.rb
179
- - spec/sprockets_spec.rb
180
- - spec/utils_spec.rb
181
189
  homepage: http://rubygems.org/gems/i18n-js
182
190
  licenses:
183
191
  - MIT
@@ -198,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
206
  version: 1.3.1
199
207
  requirements: []
200
208
  rubyforge_project:
201
- rubygems_version: 2.4.6
209
+ rubygems_version: 2.5.0
202
210
  signing_key:
203
211
  specification_version: 4
204
212
  summary: It's a small library to provide the Rails I18n translations on the Javascript.
@@ -226,18 +234,18 @@ test_files:
226
234
  - spec/fixtures/no_config.yml
227
235
  - spec/fixtures/no_scope.yml
228
236
  - spec/fixtures/simple_scope.yml
229
- - spec/i18n_js_fallback_locales_spec.rb
230
- - spec/i18n_js_spec.rb
231
237
  - spec/js/currency.spec.js
232
238
  - spec/js/current_locale.spec.js
233
239
  - spec/js/dates.spec.js
234
240
  - spec/js/defaults.spec.js
241
+ - spec/js/extend.spec.js
235
242
  - spec/js/interpolation.spec.js
236
243
  - spec/js/jasmine/MIT.LICENSE
237
244
  - spec/js/jasmine/jasmine-html.js
238
245
  - spec/js/jasmine/jasmine.css
239
246
  - spec/js/jasmine/jasmine.js
240
247
  - spec/js/jasmine/jasmine_favicon.png
248
+ - spec/js/locales.spec.js
241
249
  - spec/js/localization.spec.js
242
250
  - spec/js/numbers.spec.js
243
251
  - spec/js/placeholder.spec.js
@@ -249,8 +257,10 @@ test_files:
249
257
  - spec/js/translate.spec.js
250
258
  - spec/js/translations.js
251
259
  - spec/js/utility_functions.spec.js
252
- - spec/segment_spec.rb
260
+ - spec/ruby/i18n/js/dependencies_spec.rb
261
+ - spec/ruby/i18n/js/fallback_locales_spec.rb
262
+ - spec/ruby/i18n/js/segment_spec.rb
263
+ - spec/ruby/i18n/js/utils_spec.rb
264
+ - spec/ruby/i18n/js_spec.rb
253
265
  - spec/spec_helper.rb
254
- - spec/sprockets_spec.rb
255
- - spec/utils_spec.rb
256
266
  has_rdoc: