i18n-js 3.0.0.rc3 → 3.0.0.rc4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 065703ea709f170b5326ad0bbbe60039cfcdaa30
4
+ data.tar.gz: 06edb6364fd9131dac979dd9052e5c94e2602d08
5
+ SHA512:
6
+ metadata.gz: 882399d880781f54c2a41febc8cd069a8e5f360219be69310a70071e511fc317c9331784ebf1ec94a76ec0555a835061877dc68185e2b322132a4ebef0a7fa94
7
+ data.tar.gz: db1adab1b748f5f06e0b2c58feee72a60348e56d99eb22421c6e46d02de5e041add56cd858ca1d616dbf06b504b8a62c83aadc3dd4f2858271a286694cb06211
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  pkg
2
+ node_modules
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
  gemspec
data/Gemfile.lock CHANGED
@@ -1,43 +1,52 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n-js (3.0.0.rc3)
4
+ i18n-js (3.0.0.rc4)
5
5
  i18n
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (3.2.8)
10
+ activesupport (3.2.12)
11
11
  i18n (~> 0.6)
12
12
  multi_json (~> 1.0)
13
13
  awesome_print (1.1.0)
14
- coderay (1.0.8)
15
- diff-lcs (1.1.3)
16
- i18n (0.6.1)
14
+ coderay (1.0.9)
15
+ diff-lcs (1.2.1)
16
+ i18n (0.6.4)
17
17
  method_source (0.8.1)
18
- multi_json (1.3.6)
19
- pry (0.9.10)
18
+ multi_json (1.6.1)
19
+ pry (0.9.12)
20
20
  coderay (~> 1.0.5)
21
21
  method_source (~> 0.8)
22
- slop (~> 3.3.1)
23
- rake (0.9.2.2)
24
- rspec (2.11.0)
25
- rspec-core (~> 2.11.0)
26
- rspec-expectations (~> 2.11.0)
27
- rspec-mocks (~> 2.11.0)
28
- rspec-core (2.11.1)
29
- rspec-expectations (2.11.3)
30
- diff-lcs (~> 1.1.3)
31
- rspec-mocks (2.11.3)
32
- slop (3.3.3)
22
+ slop (~> 3.4)
23
+ pry-meta (0.0.5)
24
+ awesome_print
25
+ pry
26
+ pry-nav
27
+ pry-remote
28
+ pry-nav (0.2.3)
29
+ pry (~> 0.9.10)
30
+ pry-remote (0.1.7)
31
+ pry (~> 0.9)
32
+ slop (~> 3.0)
33
+ rake (10.0.3)
34
+ rspec (2.13.0)
35
+ rspec-core (~> 2.13.0)
36
+ rspec-expectations (~> 2.13.0)
37
+ rspec-mocks (~> 2.13.0)
38
+ rspec-core (2.13.0)
39
+ rspec-expectations (2.13.0)
40
+ diff-lcs (>= 1.1.3, < 2.0)
41
+ rspec-mocks (2.13.0)
42
+ slop (3.4.3)
33
43
 
34
44
  PLATFORMS
35
45
  ruby
36
46
 
37
47
  DEPENDENCIES
38
48
  activesupport
39
- awesome_print
40
49
  i18n-js!
41
- pry
50
+ pry-meta
42
51
  rake
43
52
  rspec
data/README.md CHANGED
@@ -65,6 +65,8 @@ Set your locale is easy as
65
65
  I18n.currentLocale();
66
66
  // pt-BR
67
67
 
68
+ **NOTE:** Just make sure you apply your configuration **after i18n.js** is loaded. Otherwise, your settings will be ignored.
69
+
68
70
  In practice, you'll have something like the following in your `application.html.erb`:
69
71
 
70
72
  <script type="text/javascript">
@@ -143,7 +145,7 @@ If you're using the same scope over and over again, you may use the `scope` opti
143
145
  I18n.t("email", options);
144
146
  I18n.t("username", options);
145
147
 
146
- You also provide an array as scope.
148
+ You can also provide an array as scope.
147
149
 
148
150
  // use the greetings.hello scope
149
151
  I18n.t(["greetings", "hello"]);
@@ -267,10 +269,6 @@ The only requirement is that you need to set the `translations` attribute like f
267
269
  message: "Uma mensagem especial para você"
268
270
  }
269
271
 
270
- ## Troubleshooting
271
-
272
- 1. Want to support oldIE? Then you need to include something like [augment.js](http://augmentjs.com) or [es5-shim](https://github.com/kriskowal/es5-shim/).
273
-
274
272
  ## Maintainer
275
273
 
276
274
  - Nando Vieira - <http://nandovieira.com.br>
@@ -294,11 +292,11 @@ You can run I18n tests using Node.js or your browser.
294
292
 
295
293
  To use Node.js, install the `jasmine-node` library:
296
294
 
297
- $ npm install jasmine-node -g
295
+ $ npm install jasmine-node
298
296
 
299
297
  Then execute the following command from the lib's root directory:
300
298
 
301
- $ jasmine-node spec/js
299
+ $ npm test
302
300
 
303
301
  To run using your browser, just open the `spec/js/specs.html` file.
304
302
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ RSpec::Core::RakeTask.new(:"spec:ruby")
6
6
 
7
7
  desc "Run JavaScript specs"
8
8
  task "spec:js" do
9
- system "jasmine-node", "spec/js"
9
+ system "npm", "test"
10
10
  end
11
11
 
12
12
  desc "Run all specs"
@@ -116,8 +116,7 @@
116
116
  return list;
117
117
  };
118
118
 
119
- //
120
- //
119
+ // Hold pluralization rules.
121
120
  I18n.pluralization = {};
122
121
 
123
122
  // Return the pluralizer for a specific locale.
@@ -176,12 +175,12 @@
176
175
  while (scopes.length) {
177
176
  translations = translations[scopes.shift()];
178
177
 
179
- if (!translations) {
178
+ if (translations === undefined || translations === null) {
180
179
  break;
181
180
  }
182
181
  }
183
182
 
184
- if (translations) {
183
+ if (translations !== undefined && translations !== null) {
185
184
  return translations;
186
185
  }
187
186
  }
@@ -230,7 +229,7 @@
230
229
  options = this.prepareOptions(options);
231
230
  var translation = this.lookup(scope, options);
232
231
 
233
- if (!translation) {
232
+ if (translation === undefined || translation === null) {
234
233
  return this.missingTranslation(scope);
235
234
  }
236
235
 
@@ -332,9 +331,9 @@
332
331
  //
333
332
  I18n.toNumber = function(number, options) {
334
333
  options = this.prepareOptions(
335
- options,
336
- this.lookup("number.format"),
337
- {precision: 3, separator: ".", delimiter: ",", strip_insignificant_zeros: false}
334
+ options
335
+ , this.lookup("number.format")
336
+ , {precision: 3, separator: ".", delimiter: ",", strip_insignificant_zeros: false}
338
337
  );
339
338
 
340
339
  var negative = number < 0
@@ -387,10 +386,10 @@
387
386
  //
388
387
  I18n.toCurrency = function(number, options) {
389
388
  options = this.prepareOptions(
390
- options,
391
- this.lookup("number.currency.format"),
392
- this.lookup("number.format"),
393
- {unit: "$", precision: 2, format: "%u%n", delimiter: ",", separator: "."}
389
+ options
390
+ , this.lookup("number.currency.format")
391
+ , this.lookup("number.format")
392
+ , {unit: "$", precision: 2, format: "%u%n", delimiter: ",", separator: "."}
394
393
  );
395
394
 
396
395
  number = this.toNumber(number, options);
@@ -545,9 +544,8 @@
545
544
  hour12 = 12;
546
545
  }
547
546
 
548
- var padding = function(n) {
549
- var s = "0" + n.toString();
550
- return s.substr(s.length - 2);
547
+ var padding = function(number) {
548
+ return ("0" + number.toString()).substr(-2);
551
549
  };
552
550
 
553
551
  format = format.replace("%a", options.abbr_day_names[weekDay]);
@@ -577,10 +575,9 @@
577
575
  return format;
578
576
  };
579
577
 
580
- //
581
- //
582
- I18n.toTime = function(scope, d) {
583
- var date = this.parseDate(d)
578
+ // Convert the given dateString into a formatted date.
579
+ I18n.toTime = function(scope, dateString) {
580
+ var date = this.parseDate(dateString)
584
581
  , format = this.lookup(scope)
585
582
  ;
586
583
 
@@ -595,22 +592,20 @@
595
592
  return this.strftime(date, format);
596
593
  };
597
594
 
598
- //
599
- //
595
+ // Convert a number into a formatted percentage value.
600
596
  I18n.toPercentage = function(number, options) {
601
597
  options = this.prepareOptions(
602
- options,
603
- this.lookup("number.percentage.format"),
604
- this.lookup("number.format"),
605
- {precision: 3, separator: ".", delimiter: ""}
598
+ options
599
+ , this.lookup("number.percentage.format")
600
+ , this.lookup("number.format")
601
+ , {precision: 3, separator: ".", delimiter: ""}
606
602
  );
607
603
 
608
604
  number = this.toNumber(number, options);
609
605
  return number + "%";
610
606
  };
611
607
 
612
- //
613
- //
608
+ // Convert a number into a readable size representation.
614
609
  I18n.toHumanSize = function(number, options) {
615
610
  var kb = 1024
616
611
  , size = number
@@ -633,8 +628,8 @@
633
628
  }
634
629
 
635
630
  options = this.prepareOptions(
636
- options,
637
- {precision: precision, format: "%n%u", delimiter: ""}
631
+ options
632
+ , {precision: precision, format: "%n%u", delimiter: ""}
638
633
  );
639
634
 
640
635
  number = this.toNumber(size, options);
@@ -650,4 +645,4 @@
650
645
  I18n.t = I18n.translate;
651
646
  I18n.l = I18n.localize;
652
647
  I18n.p = I18n.pluralize;
653
- })(typeof(exports) === "undefined" ? this["I18n"] = {} : exports);
648
+ })(typeof(exports) === "undefined" ? {} : exports);
@@ -0,0 +1,93 @@
1
+ // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
2
+ if (!Array.prototype.indexOf) {
3
+ Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
4
+ "use strict";
5
+ if (this == null) {
6
+ throw new TypeError();
7
+ }
8
+ var t = Object(this);
9
+ var len = t.length >>> 0;
10
+ if (len === 0) {
11
+ return -1;
12
+ }
13
+ var n = 0;
14
+ if (arguments.length > 1) {
15
+ n = Number(arguments[1]);
16
+ if (n != n) { // shortcut for verifying if it's NaN
17
+ n = 0;
18
+ } else if (n != 0 && n != Infinity && n != -Infinity) {
19
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
20
+ }
21
+ }
22
+ if (n >= len) {
23
+ return -1;
24
+ }
25
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
26
+ for (; k < len; k++) {
27
+ if (k in t && t[k] === searchElement) {
28
+ return k;
29
+ }
30
+ }
31
+ return -1;
32
+ }
33
+ }
34
+
35
+ // Production steps of ECMA-262, Edition 5, 15.4.4.18
36
+ // Reference: http://es5.github.com/#x15.4.4.18
37
+ // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach
38
+ if ( !Array.prototype.forEach ) {
39
+
40
+ Array.prototype.forEach = function forEach( callback, thisArg ) {
41
+
42
+ var T, k;
43
+
44
+ if ( this == null ) {
45
+ throw new TypeError( "this is null or not defined" );
46
+ }
47
+
48
+ // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
49
+ var O = Object(this);
50
+
51
+ // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
52
+ // 3. Let len be ToUint32(lenValue).
53
+ var len = O.length >>> 0; // Hack to convert O.length to a UInt32
54
+
55
+ // 4. If IsCallable(callback) is false, throw a TypeError exception.
56
+ // See: http://es5.github.com/#x9.11
57
+ if ( {}.toString.call(callback) !== "[object Function]" ) {
58
+ throw new TypeError( callback + " is not a function" );
59
+ }
60
+
61
+ // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
62
+ if ( thisArg ) {
63
+ T = thisArg;
64
+ }
65
+
66
+ // 6. Let k be 0
67
+ k = 0;
68
+
69
+ // 7. Repeat, while k < len
70
+ while( k < len ) {
71
+
72
+ var kValue;
73
+
74
+ // a. Let Pk be ToString(k).
75
+ // This is implicit for LHS operands of the in operator
76
+ // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
77
+ // This step can be combined with c
78
+ // c. If kPresent is true, then
79
+ if ( Object.prototype.hasOwnProperty.call(O, k) ) {
80
+
81
+ // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
82
+ kValue = O[ k ];
83
+
84
+ // ii. Call the Call internal method of callback with T as the this value and
85
+ // argument list containing kValue, k, and O.
86
+ callback.call( T, kValue, k, O );
87
+ }
88
+ // d. Increase k by 1.
89
+ k++;
90
+ }
91
+ // 8. return undefined
92
+ };
93
+ }
@@ -1,3 +1,4 @@
1
+ //= require i18n/shims
1
2
  //= require i18n
2
3
  //= require_self
3
- ;I18n.translations = <%= I18n::JS.filtered_translations.to_json %>;
4
+ ;I18n.translations = <%= I18n::JS.filtered_translations.to_json %>;
data/i18n-js.gemspec CHANGED
@@ -21,6 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency "activesupport"
22
22
  s.add_development_dependency "rspec"
23
23
  s.add_development_dependency "rake"
24
- s.add_development_dependency "pry"
25
- s.add_development_dependency "awesome_print"
24
+ s.add_development_dependency "pry-meta"
26
25
  end
@@ -4,7 +4,7 @@ module I18n
4
4
  MAJOR = 3
5
5
  MINOR = 0
6
6
  PATCH = 0
7
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.rc3"
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.rc4"
8
8
  end
9
9
  end
10
10
  end
data/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "i18n-js",
3
+ "version": "0.0.0",
4
+ "devDependencies": {
5
+ "jasmine-node": "*"
6
+ },
7
+
8
+ "scripts": {
9
+ "test": "./node_modules/.bin/jasmine-node spec/js"
10
+ }
11
+ }
@@ -112,4 +112,9 @@ describe("Translate", function(){
112
112
  actual = I18n.t("greetings•stranger");
113
113
  expect(actual).toEqual("Hello stranger!");
114
114
  });
115
+
116
+ it("returns boolean values", function() {
117
+ expect(I18n.t("booleans.yes")).toEqual(true);
118
+ expect(I18n.t("booleans.no")).toEqual(false);
119
+ });
115
120
  });
@@ -5,6 +5,11 @@
5
5
  Translations.en = {
6
6
  hello: "Hello World!"
7
7
 
8
+ , booleans: {
9
+ yes: true,
10
+ no: false
11
+ }
12
+
8
13
  , greetings: {
9
14
  stranger: "Hello stranger!"
10
15
  , name: "Hello {{name}}!"
metadata CHANGED
@@ -1,110 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc3
5
- prerelease: 6
4
+ version: 3.0.0.rc4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nando Vieira
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-17 00:00:00.000000000 Z
11
+ date: 2013-03-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: i18n
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
- name: pry
70
+ name: pry-meta
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: awesome_print
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
80
+ - - '>='
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
83
  description: It's a small library to provide the Rails I18n translations on the Javascript.
@@ -120,6 +93,7 @@ files:
120
93
  - README.md
121
94
  - Rakefile
122
95
  - app/assets/javascripts/i18n.js
96
+ - app/assets/javascripts/i18n/shims.js
123
97
  - app/assets/javascripts/i18n/translations.js.erb
124
98
  - i18n-js.gemspec
125
99
  - lib/i18n-js.rb
@@ -127,6 +101,7 @@ files:
127
101
  - lib/i18n/js/engine.rb
128
102
  - lib/i18n/js/middleware.rb
129
103
  - lib/i18n/js/version.rb
104
+ - package.json
130
105
  - spec/fixtures/custom_path.yml
131
106
  - spec/fixtures/default.yml
132
107
  - spec/fixtures/js_file_per_locale.yml
@@ -158,26 +133,25 @@ files:
158
133
  - spec/spec_helper.rb
159
134
  homepage: http://rubygems.org/gems/i18n-js
160
135
  licenses: []
136
+ metadata: {}
161
137
  post_install_message:
162
138
  rdoc_options: []
163
139
  require_paths:
164
140
  - lib
165
141
  required_ruby_version: !ruby/object:Gem::Requirement
166
- none: false
167
142
  requirements:
168
- - - ! '>='
143
+ - - '>='
169
144
  - !ruby/object:Gem::Version
170
145
  version: '0'
171
146
  required_rubygems_version: !ruby/object:Gem::Requirement
172
- none: false
173
147
  requirements:
174
- - - ! '>'
148
+ - - '>'
175
149
  - !ruby/object:Gem::Version
176
150
  version: 1.3.1
177
151
  requirements: []
178
152
  rubyforge_project:
179
- rubygems_version: 1.8.23
153
+ rubygems_version: 2.0.2
180
154
  signing_key:
181
- specification_version: 3
155
+ specification_version: 4
182
156
  summary: It's a small library to provide the Rails I18n translations on the Javascript.
183
157
  test_files: []