i18n-js 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
@@ -1,30 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n-js (1.0.2)
4
+ i18n-js (1.1.0)
5
5
  i18n
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activesupport (3.0.5)
10
+ activesupport (3.0.9)
11
11
  archive-tar-minitar (0.5.2)
12
- columnize (0.3.2)
12
+ columnize (0.3.4)
13
13
  diff-lcs (1.1.2)
14
14
  fakeweb (1.3.0)
15
- i18n (0.5.0)
16
- linecache19 (0.5.11)
15
+ i18n (0.6.0)
16
+ linecache19 (0.5.12)
17
17
  ruby_core_source (>= 0.1.4)
18
- notifier (0.1.2)
19
- rspec (2.5.0)
20
- rspec-core (~> 2.5.0)
21
- rspec-expectations (~> 2.5.0)
22
- rspec-mocks (~> 2.5.0)
23
- rspec-core (2.5.1)
24
- rspec-expectations (2.5.0)
18
+ notifier (0.1.3)
19
+ rake (0.8.7)
20
+ rspec (2.6.0)
21
+ rspec-core (~> 2.6.0)
22
+ rspec-expectations (~> 2.6.0)
23
+ rspec-mocks (~> 2.6.0)
24
+ rspec-core (2.6.4)
25
+ rspec-expectations (2.6.0)
25
26
  diff-lcs (~> 1.1.2)
26
- rspec-mocks (2.5.0)
27
- ruby-debug-base19 (0.11.24)
27
+ rspec-mocks (2.6.0)
28
+ ruby-debug-base19 (0.11.25)
28
29
  columnize (>= 0.3.1)
29
30
  linecache19 (>= 0.5.11)
30
31
  ruby_core_source (>= 0.1.4)
@@ -32,7 +33,7 @@ GEM
32
33
  columnize (>= 0.3.1)
33
34
  linecache19 (>= 0.5.11)
34
35
  ruby-debug-base19 (>= 0.11.19)
35
- ruby_core_source (0.1.4)
36
+ ruby_core_source (0.1.5)
36
37
  archive-tar-minitar (>= 0.5.2)
37
38
  spec-js (0.1.0.beta.3)
38
39
  notifier
@@ -41,9 +42,10 @@ PLATFORMS
41
42
  ruby
42
43
 
43
44
  DEPENDENCIES
44
- activesupport (~> 3.0.0)
45
+ activesupport (>= 3.0.0)
45
46
  fakeweb
46
47
  i18n-js!
47
- rspec (~> 2.5.0)
48
+ rake (= 0.8.7)
49
+ rspec (~> 2.6)
48
50
  ruby-debug19
49
51
  spec-js (~> 0.1.0.beta.0)
@@ -17,21 +17,22 @@ This library has been tested on:
17
17
 
18
18
  === Setting up
19
19
 
20
+ ==== Rails <= 3.0
20
21
  Run <tt>rake i18n:setup</tt> to copy <tt>i18n.js</tt> to your javascript directory and <tt>i18n-js.yml</tt> to your config folder (if not already present). Then you're ready to go!
21
22
 
22
- Every time your application is started, the translations messages defined in your configuration file will be generated.
23
+ ==== Rails >= 3.1
24
+ Run <tt>rake i18n:setup</tt> to copy <tt>i18n-js.yml</tt> to your config folder (if not already present). You should change the path in <tt>i18n.js.yml</tt> to <tt>app/assets/javascripts/i18n</tt> to make full use of the asset pipeline.
25
+ Next add the following lines to your application.js to make the javascripts and translations available to your app:
23
26
 
24
- To speed up the development process, you can automatically export your messages by adding something
25
- like this to your <tt>ApplicationController</tt>:
27
+ //= require i18n
28
+ //= require i18n/translations
26
29
 
27
- class ApplicationController < ActionController::Base
28
- before_filter :export_i18n_messages
30
+ If you don't want to use the asset pipeline, just disable it on your configuration file by setting <tt>asset_pipeline</tt> to <tt>false</tt>.
29
31
 
30
- private
31
- def export_i18n_messages
32
- SimplesIdeias::I18n.export! if Rails.env.development?
33
- end
34
- end
32
+ ==== Exporting translations
33
+
34
+ You can export the translations file by running `rake i18n:js:export`. Translations will be automatically exported in development mode, but you can set the <tt>auto_export</tt> option
35
+ to <tt>true</tt> on your configuration file if you want to export translations when your app is booted.
35
36
 
36
37
  ==== Configuration
37
38
 
@@ -258,7 +259,7 @@ To run Ruby tests, you need to install http://github.com/rspec/rspec
258
259
 
259
260
  To run JavaScript tests, you need to install http://github.com/fnando/spec-js
260
261
 
261
- gem install specjs
262
+ gem install spec-js --pre
262
263
 
263
264
  Then just run `rake spec`.
264
265
 
@@ -0,0 +1,18 @@
1
+ # Find more details about this configuration file
2
+ # at http://github.com/fnando/i18n-js
3
+
4
+ # Automatically export translations when running in
5
+ # development mode, or once when your app is booted
6
+ # in production mode.
7
+ auto_export: no
8
+
9
+ # Split context in several files.
10
+ # By default only one file is exported.
11
+ translations:
12
+ - file: "public/javascripts/translations.js"
13
+ only: "*"
14
+
15
+ # Use Rails 3.1 asset pipeline feature.
16
+ # You can disable it by changing the following
17
+ # line to "no".
18
+ asset_pipeline: yes
@@ -19,8 +19,9 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency "i18n"
21
21
  s.add_development_dependency "fakeweb"
22
- s.add_development_dependency "activesupport", "~> 3.0.0"
23
- s.add_development_dependency "rspec", "~> 2.5.0"
22
+ s.add_development_dependency "activesupport", ">= 3.0.0"
23
+ s.add_development_dependency "rspec", "~> 2.6"
24
24
  s.add_development_dependency "ruby-debug19"
25
25
  s.add_development_dependency "spec-js", "~> 0.1.0.beta.0"
26
+ s.add_development_dependency "rake", "0.8.7"
26
27
  end
@@ -5,6 +5,7 @@ module SimplesIdeias
5
5
  extend self
6
6
 
7
7
  require "i18n-js/railtie" if Rails.version >= "3.0"
8
+ require "i18n-js/engine" if Rails.version >= "3.1"
8
9
 
9
10
  # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
10
11
  MERGER = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2 }
@@ -13,8 +14,16 @@ module SimplesIdeias
13
14
  Rails.root.join("config/i18n-js.yml")
14
15
  end
15
16
 
17
+ def export_dir
18
+ if Rails.version >= "3.1" && config.fetch(:asset_pipeline, true)
19
+ "app/assets/javascripts/i18n"
20
+ else
21
+ "public/javascripts"
22
+ end
23
+ end
24
+
16
25
  def javascript_file
17
- Rails.root.join("public/javascripts/i18n.js")
26
+ Rails.root.join(export_dir, "i18n.js")
18
27
  end
19
28
 
20
29
  # Export translations to JavaScript, considering settings
@@ -32,14 +41,23 @@ module SimplesIdeias
32
41
  end
33
42
  end
34
43
  else
35
- save translations, "public/javascripts/translations.js"
44
+ save translations, "#{export_dir}/translations.js"
36
45
  end
37
46
  end
38
47
 
39
48
  # Load configuration file for partial exporting and
40
49
  # custom output directory
41
50
  def config
42
- HashWithIndifferentAccess.new YAML.load_file(config_file)
51
+ if config?
52
+ YAML.load_file(config_file).with_indifferent_access
53
+ else
54
+ {}
55
+ end
56
+ end
57
+
58
+ # Check if translations can be automatically exported.
59
+ def auto_export?
60
+ Rails.env.development? || (config? && config[:auto_export])
43
61
  end
44
62
 
45
63
  # Check if configuration file exist
@@ -50,8 +68,8 @@ module SimplesIdeias
50
68
  # Copy configuration and JavaScript library files to
51
69
  # <tt>config/i18n-js.yml</tt> and <tt>public/javascripts/i18n.js</tt>.
52
70
  def setup!
53
- FileUtils.cp File.dirname(__FILE__) + "/../source/i18n.js", javascript_file
54
- FileUtils.cp(File.dirname(__FILE__) + "/../source/i18n-js.yml", config_file) unless config?
71
+ FileUtils.cp(File.dirname(__FILE__) + "/../vendor/assets/javascripts/i18n.js", javascript_file) unless Rails.version >= "3.1"
72
+ FileUtils.cp(File.dirname(__FILE__) + "/../config/i18n-js.yml", config_file) unless config?
55
73
  end
56
74
 
57
75
  # Retrieve an updated JavaScript library from Github.
@@ -0,0 +1,7 @@
1
+ module SimplesIdeias
2
+ module I18n
3
+ class Engine < ::Rails::Engine
4
+ # Engine so the vendor directory gets recognized by the asset pipeline
5
+ end
6
+ end
7
+ end
@@ -2,7 +2,13 @@ module SimplesIdeias
2
2
  module I18n
3
3
  class Railtie < Rails::Railtie
4
4
  rake_tasks do
5
- load File.dirname(__FILE__) + "/../tasks/i18n-js_tasks.rake"
5
+ require "i18n-js/rake"
6
+ end
7
+
8
+ config.to_prepare do
9
+ SimplesIdeias::I18n.tap do |i18n|
10
+ i18n.export! if i18n.auto_export?
11
+ end
6
12
  end
7
13
  end
8
14
  end
@@ -1,4 +1,4 @@
1
- namespace :i18n do
1
+ namespace "i18n:js" do
2
2
  desc "Copy i18n.js and configuration file"
3
3
  task :setup => :environment do
4
4
  SimplesIdeias::I18n.setup!
@@ -2,8 +2,8 @@ module SimplesIdeias
2
2
  module I18n
3
3
  module Version
4
4
  MAJOR = 1
5
- MINOR = 0
6
- PATCH = 2
5
+ MINOR = 1
6
+ PATCH = 0
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
8
  end
9
9
  end
@@ -1,4 +1,4 @@
1
- load("source/i18n.js");
1
+ load("vendor/assets/javascripts/i18n.js");
2
2
 
3
3
  describe("I18n.js", function(){
4
4
  before(function() {
@@ -34,7 +34,7 @@ describe("I18n.js", function(){
34
34
  one: "Byte",
35
35
  other: "Bytes"
36
36
  },
37
-
37
+
38
38
  "kb": "KB",
39
39
  "mb": "MB",
40
40
  "gb": "GB",
@@ -94,128 +94,128 @@ describe("I18n.js", function(){
94
94
  }
95
95
  };
96
96
  });
97
-
97
+
98
98
  specify("with default options", function(){
99
99
  expect(I18n.defaultLocale).toBeEqualTo("en");
100
100
  expect(I18n.locale).toBeEqualTo(null);
101
101
  expect(I18n.currentLocale()).toBeEqualTo("en");
102
102
  });
103
-
103
+
104
104
  specify("with custom locale", function(){
105
105
  I18n.locale = "pt-BR";
106
106
  expect(I18n.currentLocale()).toBeEqualTo("pt-BR");
107
107
  });
108
-
108
+
109
109
  specify("aliases", function(){
110
110
  expect(I18n.t).toBe(I18n.translate);
111
111
  expect(I18n.l).toBe(I18n.localize);
112
112
  expect(I18n.p).toBe(I18n.pluralize);
113
113
  });
114
-
114
+
115
115
  specify("translation with single scope", function(){
116
116
  expect(I18n.t("hello")).toBeEqualTo("Hello World!");
117
117
  });
118
-
118
+
119
119
  specify("translation as object", function(){
120
120
  expect(I18n.t("greetings")).toBeInstanceOf(Object);
121
121
  });
122
-
122
+
123
123
  specify("translation with invalid scope shall not block", function(){
124
124
  actual = I18n.t("invalid.scope.shall.not.block");
125
125
  expected = '[missing "en.invalid.scope.shall.not.block" translation]';
126
126
  expect(actual).toBeEqualTo(expected);
127
127
  });
128
-
128
+
129
129
  specify("translation for single scope on a custom locale", function(){
130
130
  I18n.locale = "pt-BR";
131
131
  expect(I18n.t("hello")).toBeEqualTo("Olá Mundo!");
132
132
  });
133
-
133
+
134
134
  specify("translation for multiple scopes", function(){
135
135
  expect(I18n.t("greetings.stranger")).toBeEqualTo("Hello stranger!");
136
136
  });
137
-
137
+
138
138
  specify("single interpolation", function(){
139
139
  actual = I18n.t("greetings.name", {name: "John Doe"});
140
140
  expect(actual).toBeEqualTo("Hello John Doe!");
141
141
  });
142
-
142
+
143
143
  specify("multiple interpolation", function(){
144
144
  actual = I18n.t("profile.details", {name: "John Doe", age: 27});
145
145
  expect(actual).toBeEqualTo("John Doe is 27-years old");
146
146
  });
147
-
147
+
148
148
  specify("translation with count option", function(){
149
149
  expect(I18n.t("inbox", {count: 0})).toBeEqualTo("You have no messages");
150
150
  expect(I18n.t("inbox", {count: 1})).toBeEqualTo("You have 1 message");
151
151
  expect(I18n.t("inbox", {count: 5})).toBeEqualTo("You have 5 messages");
152
152
  });
153
-
153
+
154
154
  specify("translation with count option and multiple placeholders", function(){
155
155
  actual = I18n.t("unread", {unread: 5, count: 1});
156
156
  expect(actual).toBeEqualTo("You have 1 new message (5 unread)");
157
-
157
+
158
158
  actual = I18n.t("unread", {unread: 2, count: 10});
159
159
  expect(actual).toBeEqualTo("You have 10 new messages (2 unread)");
160
-
160
+
161
161
  actual = I18n.t("unread", {unread: 5, count: 0});
162
162
  expect(actual).toBeEqualTo("You have no new messages (5 unread)");
163
163
  });
164
-
164
+
165
165
  specify("missing translation with count option", function(){
166
166
  actual = I18n.t("invalid", {count: 1});
167
167
  expect(actual).toBeEqualTo('[missing "en.invalid" translation]');
168
-
168
+
169
169
  I18n.translations.en.inbox.one = null;
170
170
  actual = I18n.t("inbox", {count: 1});
171
171
  expect(actual).toBeEqualTo('[missing "en.inbox.one" translation]');
172
172
  });
173
-
173
+
174
174
  specify("pluralization", function(){
175
175
  expect(I18n.p(0, "inbox")).toBeEqualTo("You have no messages");
176
176
  expect(I18n.p(1, "inbox")).toBeEqualTo("You have 1 message");
177
177
  expect(I18n.p(5, "inbox")).toBeEqualTo("You have 5 messages");
178
178
  });
179
-
179
+
180
180
  specify("pluralize should return 'other' scope", function(){
181
181
  I18n.translations["en"]["inbox"]["zero"] = null;
182
182
  expect(I18n.p(0, "inbox")).toBeEqualTo("You have 0 messages");
183
183
  });
184
-
184
+
185
185
  specify("pluralize should return 'zero' scope", function(){
186
186
  I18n.translations["en"]["inbox"]["zero"] = "No messages (zero)";
187
187
  I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
188
-
188
+
189
189
  expect(I18n.p(0, "inbox")).toBeEqualTo("No messages (zero)");
190
190
  });
191
-
191
+
192
192
  specify("pluralize should return 'none' scope", function(){
193
193
  I18n.translations["en"]["inbox"]["zero"] = null;
194
194
  I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
195
-
195
+
196
196
  expect(I18n.p(0, "inbox")).toBeEqualTo("No messages (none)");
197
197
  });
198
-
198
+
199
199
  specify("pluralize with negative values", function(){
200
200
  expect(I18n.p(-1, "inbox")).toBeEqualTo("You have -1 message");
201
201
  expect(I18n.p(-5, "inbox")).toBeEqualTo("You have -5 messages");
202
202
  });
203
-
203
+
204
204
  specify("pluralize with missing scope", function(){
205
205
  expect(I18n.p(-1, "missing")).toBeEqualTo('[missing "en.missing" translation]');
206
206
  });
207
-
207
+
208
208
  specify("pluralize with multiple placeholders", function(){
209
209
  actual = I18n.p(1, "unread", {unread: 5});
210
210
  expect(actual).toBeEqualTo("You have 1 new message (5 unread)");
211
-
211
+
212
212
  actual = I18n.p(10, "unread", {unread: 2});
213
213
  expect(actual).toBeEqualTo("You have 10 new messages (2 unread)");
214
-
214
+
215
215
  actual = I18n.p(0, "unread", {unread: 5});
216
216
  expect(actual).toBeEqualTo("You have no new messages (5 unread)");
217
217
  });
218
-
218
+
219
219
  specify("pluralize should allow empty strings", function(){
220
220
  I18n.translations["en"]["inbox"]["zero"] = "";
221
221
 
@@ -233,7 +233,7 @@ describe("I18n.js", function(){
233
233
  expect(I18n.toNumber(12345678)).toBeEqualTo("12,345,678.000");
234
234
  expect(I18n.toNumber(123456789)).toBeEqualTo("123,456,789.000");
235
235
  });
236
-
236
+
237
237
  specify("negative numbers with default settings", function(){
238
238
  expect(I18n.toNumber(-1)).toBeEqualTo("-1.000");
239
239
  expect(I18n.toNumber(-12)).toBeEqualTo("-12.000");
@@ -245,17 +245,17 @@ describe("I18n.js", function(){
245
245
  expect(I18n.toNumber(-12345678)).toBeEqualTo("-12,345,678.000");
246
246
  expect(I18n.toNumber(-123456789)).toBeEqualTo("-123,456,789.000");
247
247
  });
248
-
248
+
249
249
  specify("numbers with partial translation and default options", function(){
250
250
  I18n.translations.en.number = {
251
251
  format: {
252
252
  precision: 2
253
253
  }
254
254
  };
255
-
255
+
256
256
  expect(I18n.toNumber(1234)).toBeEqualTo("1,234.00");
257
257
  });
258
-
258
+
259
259
  specify("numbers with full translation and default options", function(){
260
260
  I18n.translations.en.number = {
261
261
  format: {
@@ -264,23 +264,23 @@ describe("I18n.js", function(){
264
264
  precision: 2
265
265
  }
266
266
  };
267
-
267
+
268
268
  expect(I18n.toNumber(1234)).toBeEqualTo("1.234,00");
269
269
  });
270
-
270
+
271
271
  specify("numbers with some custom options that should be merged with default options", function(){
272
272
  expect(I18n.toNumber(1234, {precision: 0})).toBeEqualTo("1,234");
273
273
  expect(I18n.toNumber(1234, {separator: '-'})).toBeEqualTo("1,234-000");
274
274
  expect(I18n.toNumber(1234, {delimiter: '-'})).toBeEqualTo("1-234.000");
275
275
  });
276
-
276
+
277
277
  specify("numbers considering options", function(){
278
278
  options = {
279
279
  precision: 2,
280
280
  separator: ",",
281
281
  delimiter: "."
282
282
  };
283
-
283
+
284
284
  expect(I18n.toNumber(1, options)).toBeEqualTo("1,00");
285
285
  expect(I18n.toNumber(12, options)).toBeEqualTo("12,00");
286
286
  expect(I18n.toNumber(123, options)).toBeEqualTo("123,00");
@@ -289,31 +289,31 @@ describe("I18n.js", function(){
289
289
  expect(I18n.toNumber(1234567, options)).toBeEqualTo("1.234.567,00");
290
290
  expect(I18n.toNumber(12345678, options)).toBeEqualTo("12.345.678,00");
291
291
  });
292
-
292
+
293
293
  specify("numbers with different precisions", function(){
294
294
  options = {separator: ".", delimiter: ","};
295
-
295
+
296
296
  options["precision"] = 2;
297
297
  expect(I18n.toNumber(1.98, options)).toBeEqualTo("1.98");
298
-
298
+
299
299
  options["precision"] = 3;
300
300
  expect(I18n.toNumber(1.98, options)).toBeEqualTo("1.980");
301
-
301
+
302
302
  options["precision"] = 2;
303
303
  expect(I18n.toNumber(1.987, options)).toBeEqualTo("1.99");
304
-
304
+
305
305
  options["precision"] = 1;
306
306
  expect(I18n.toNumber(1.98, options)).toBeEqualTo("2.0");
307
-
307
+
308
308
  options["precision"] = 0;
309
309
  expect(I18n.toNumber(1.98, options)).toBeEqualTo("2");
310
310
  });
311
-
311
+
312
312
  specify("currency with default settings", function(){
313
313
  expect(I18n.toCurrency(100.99)).toBeEqualTo("$100.99");
314
314
  expect(I18n.toCurrency(1000.99)).toBeEqualTo("$1,000.99");
315
315
  });
316
-
316
+
317
317
  specify("currency with custom settings", function(){
318
318
  I18n.translations.en.number = {
319
319
  currency: {
@@ -326,12 +326,12 @@ describe("I18n.js", function(){
326
326
  }
327
327
  }
328
328
  };
329
-
329
+
330
330
  expect(I18n.toCurrency(12)).toBeEqualTo("12,00 USD");
331
331
  expect(I18n.toCurrency(123)).toBeEqualTo("123,00 USD");
332
332
  expect(I18n.toCurrency(1234.56)).toBeEqualTo("1.234,56 USD");
333
333
  });
334
-
334
+
335
335
  specify("currency with custom settings and partial overriding", function(){
336
336
  I18n.translations.en.number = {
337
337
  currency: {
@@ -344,11 +344,11 @@ describe("I18n.js", function(){
344
344
  }
345
345
  }
346
346
  };
347
-
347
+
348
348
  expect(I18n.toCurrency(12, {precision: 0})).toBeEqualTo("12 USD");
349
349
  expect(I18n.toCurrency(123, {unit: "bucks"})).toBeEqualTo("123,00 bucks");
350
350
  });
351
-
351
+
352
352
  specify("currency with some custom options that should be merged with default options", function(){
353
353
  expect(I18n.toCurrency(1234, {precision: 0})).toBeEqualTo("$1,234");
354
354
  expect(I18n.toCurrency(1234, {unit: "º"})).toBeEqualTo("º1,234.00");
@@ -356,176 +356,185 @@ describe("I18n.js", function(){
356
356
  expect(I18n.toCurrency(1234, {delimiter: "-"})).toBeEqualTo("$1-234.00");
357
357
  expect(I18n.toCurrency(1234, {format: "%u %n"})).toBeEqualTo("$ 1,234.00");
358
358
  });
359
-
359
+
360
360
  specify("localize numbers", function(){
361
361
  expect(I18n.l("number", 1234567)).toBeEqualTo("1,234,567.000");
362
362
  });
363
-
363
+
364
364
  specify("localize currency", function(){
365
365
  expect(I18n.l("currency", 1234567)).toBeEqualTo("$1,234,567.00");
366
366
  });
367
-
367
+
368
368
  specify("parse date", function(){
369
369
  expected = new Date(2009, 0, 24, 0, 0, 0);
370
370
  actual = I18n.parseDate("2009-01-24");
371
371
  expect(actual.toString()).toBeEqualTo(expected.toString());
372
-
372
+
373
373
  expected = new Date(2009, 0, 24, 0, 15, 0);
374
374
  actual = I18n.parseDate("2009-01-24 00:15:00");
375
375
  expect(actual.toString()).toBeEqualTo(expected.toString());
376
-
376
+
377
377
  expected = new Date(2009, 0, 24, 0, 0, 15);
378
378
  actual = I18n.parseDate("2009-01-24 00:00:15");
379
379
  expect(actual.toString()).toBeEqualTo(expected.toString());
380
-
380
+
381
381
  expected = new Date(2009, 0, 24, 15, 33, 44);
382
382
  actual = I18n.parseDate("2009-01-24 15:33:44");
383
383
  expect(actual.toString()).toBeEqualTo(expected.toString());
384
-
384
+
385
385
  expected = new Date(2009, 0, 24, 0, 0, 0);
386
386
  actual = I18n.parseDate(expected.getTime());
387
387
  expect(actual.toString()).toBeEqualTo(expected.toString());
388
-
388
+
389
389
  expected = new Date(2009, 0, 24, 0, 0, 0);
390
390
  actual = I18n.parseDate("01/24/2009");
391
391
  expect(actual.toString()).toBeEqualTo(expected.toString());
392
-
392
+
393
393
  expected = new Date(2009, 0, 24, 14, 33, 55);
394
394
  actual = I18n.parseDate(expected).toString();
395
395
  expect(actual).toBeEqualTo(expected.toString());
396
-
396
+
397
397
  expected = new Date(2009, 0, 24, 15, 33, 44);
398
398
  actual = I18n.parseDate("2009-01-24T15:33:44");
399
399
  expect(actual.toString()).toBeEqualTo(expected.toString());
400
-
400
+
401
+ expected = new Date(Date.UTC(2011, 6, 20, 12, 51, 55));
402
+ actual = I18n.parseDate("2011-07-20T12:51:55+0000");
403
+ expect(actual.toString()).toBeEqualTo(expected.toString());
404
+
405
+ expected = new Date(Date.UTC(2011, 6, 20, 13, 03, 39));
406
+ actual = I18n.parseDate("Wed Jul 20 13:03:39 +0000 2011");
407
+ expect(actual.toString()).toBeEqualTo(expected.toString());
408
+
401
409
  expected = new Date(Date.UTC(2009, 0, 24, 15, 33, 44));
402
410
  actual = I18n.parseDate("2009-01-24T15:33:44Z");
403
411
  expect(actual.toString()).toBeEqualTo(expected.toString());
404
412
  });
405
-
413
+
406
414
  specify("date formatting", function(){
407
415
  I18n.locale = "pt-BR";
408
-
416
+
409
417
  // 2009-04-26 19:35:44 (Sunday)
410
418
  var date = new Date(2009, 3, 26, 19, 35, 44);
411
-
419
+
412
420
  // short week day
413
421
  expect(I18n.strftime(date, "%a")).toBeEqualTo("Dom");
414
-
422
+
415
423
  // full week day
416
424
  expect(I18n.strftime(date, "%A")).toBeEqualTo("Domingo");
417
-
425
+
418
426
  // short month
419
427
  expect(I18n.strftime(date, "%b")).toBeEqualTo("Abr");
420
-
428
+
421
429
  // full month
422
430
  expect(I18n.strftime(date, "%B")).toBeEqualTo("Abril");
423
-
431
+
424
432
  // day
425
433
  expect(I18n.strftime(date, "%d")).toBeEqualTo("26");
426
-
434
+
427
435
  // 24-hour
428
436
  expect(I18n.strftime(date, "%H")).toBeEqualTo("19");
429
-
437
+
430
438
  // 12-hour
431
439
  expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
432
-
440
+
433
441
  // month
434
442
  expect(I18n.strftime(date, "%m")).toBeEqualTo("04");
435
-
443
+
436
444
  // minutes
437
445
  expect(I18n.strftime(date, "%M")).toBeEqualTo("35");
438
-
446
+
439
447
  // meridian
440
448
  expect(I18n.strftime(date, "%p")).toBeEqualTo("PM");
441
-
449
+
442
450
  // seconds
443
451
  expect(I18n.strftime(date, "%S")).toBeEqualTo("44");
444
-
452
+
445
453
  // week day
446
454
  expect(I18n.strftime(date, "%w")).toBeEqualTo("0");
447
-
455
+
448
456
  // short year
449
457
  expect(I18n.strftime(date, "%y")).toBeEqualTo("09");
450
-
458
+
451
459
  // full year
452
460
  expect(I18n.strftime(date, "%Y")).toBeEqualTo("2009");
453
461
  });
454
-
462
+
455
463
  specify("date formatting without padding", function(){
456
464
  I18n.locale = "pt-BR";
457
-
465
+
458
466
  // 2009-04-26 19:35:44 (Sunday)
459
467
  var date = new Date(2009, 3, 9, 7, 8, 9);
460
-
468
+
461
469
  // 24-hour without padding
462
470
  expect(I18n.strftime(date, "%-H")).toBeEqualTo("7");
463
-
471
+
464
472
  // 12-hour without padding
465
473
  expect(I18n.strftime(date, "%-I")).toBeEqualTo("7");
466
-
474
+
467
475
  // minutes without padding
468
476
  expect(I18n.strftime(date, "%-M")).toBeEqualTo("8");
469
-
477
+
470
478
  // seconds without padding
471
479
  expect(I18n.strftime(date, "%-S")).toBeEqualTo("9");
472
-
480
+
473
481
  // short year without padding
474
482
  expect(I18n.strftime(date, "%-y")).toBeEqualTo("9");
475
-
483
+
476
484
  // month without padding
477
485
  expect(I18n.strftime(date, "%-m")).toBeEqualTo("4");
478
-
486
+
479
487
  // day without padding
480
488
  expect(I18n.strftime(date, "%-d")).toBeEqualTo("9");
489
+ expect(I18n.strftime(date, "%e")).toBeEqualTo("9");
481
490
  });
482
-
491
+
483
492
  specify("date formatting with padding", function(){
484
493
  I18n.locale = "pt-BR";
485
-
494
+
486
495
  // 2009-04-26 19:35:44 (Sunday)
487
496
  var date = new Date(2009, 3, 9, 7, 8, 9);
488
-
497
+
489
498
  // 24-hour
490
499
  expect(I18n.strftime(date, "%H")).toBeEqualTo("07");
491
-
500
+
492
501
  // 12-hour
493
502
  expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
494
-
503
+
495
504
  // minutes
496
505
  expect(I18n.strftime(date, "%M")).toBeEqualTo("08");
497
-
506
+
498
507
  // seconds
499
508
  expect(I18n.strftime(date, "%S")).toBeEqualTo("09");
500
-
509
+
501
510
  // short year
502
511
  expect(I18n.strftime(date, "%y")).toBeEqualTo("09");
503
-
512
+
504
513
  // month
505
514
  expect(I18n.strftime(date, "%m")).toBeEqualTo("04");
506
-
515
+
507
516
  // day
508
517
  expect(I18n.strftime(date, "%d")).toBeEqualTo("09");
509
518
  });
510
-
519
+
511
520
  specify("date formatting with negative time zone", function(){
512
521
  I18n.locale = "pt-BR";
513
522
  var date = new Date(2009, 3, 26, 19, 35, 44);
514
523
  stub(date, "getTimezoneOffset()", 345);
515
-
524
+
516
525
  expect(I18n.strftime(date, "%z")).toMatch(/^(\+|-)[\d]{4}$/);
517
526
  expect(I18n.strftime(date, "%z")).toBeEqualTo("-0545");
518
527
  });
519
-
528
+
520
529
  specify("date formatting with positive time zone", function(){
521
530
  I18n.locale = "pt-BR";
522
531
  var date = new Date(2009, 3, 26, 19, 35, 44);
523
532
  stub(date, "getTimezoneOffset()", -345);
524
-
533
+
525
534
  expect(I18n.strftime(date, "%z")).toMatch(/^(\+|-)[\d]{4}$/);
526
535
  expect(I18n.strftime(date, "%z")).toBeEqualTo("+0545");
527
536
  });
528
-
537
+
529
538
  specify("date formatting with custom meridian", function(){
530
539
  I18n.locale = "en-US";
531
540
  var date = new Date(2009, 3, 26, 19, 35, 44);
@@ -555,78 +564,78 @@ describe("I18n.js", function(){
555
564
 
556
565
  specify("localize date strings", function(){
557
566
  I18n.locale = "pt-BR";
558
-
567
+
559
568
  expect(I18n.l("date.formats.default", "2009-11-29")).toBeEqualTo("29/11/2009");
560
569
  expect(I18n.l("date.formats.short", "2009-01-07")).toBeEqualTo("07 de Janeiro");
561
570
  expect(I18n.l("date.formats.long", "2009-01-07")).toBeEqualTo("07 de Janeiro de 2009");
562
571
  });
563
-
572
+
564
573
  specify("localize time strings", function(){
565
574
  I18n.locale = "pt-BR";
566
-
575
+
567
576
  expect(I18n.l("time.formats.default", "2009-11-29 15:07:59")).toBeEqualTo("Domingo, 29 de Novembro de 2009, 15:07 h");
568
577
  expect(I18n.l("time.formats.short", "2009-01-07 09:12:35")).toBeEqualTo("07/01, 09:12 h");
569
578
  expect(I18n.l("time.formats.long", "2009-11-29 15:07:59")).toBeEqualTo("Domingo, 29 de Novembro de 2009, 15:07 h");
570
579
  });
571
-
580
+
572
581
  specify("localize percentage", function(){
573
582
  I18n.locale = "pt-BR";
574
583
  expect(I18n.l("percentage", 123.45)).toBeEqualTo("123,45%");
575
584
  });
576
-
585
+
577
586
  specify("default value for simple translation", function(){
578
587
  actual = I18n.t("warning", {defaultValue: "Warning!"});
579
588
  expect(actual).toBeEqualTo("Warning!");
580
589
  });
581
-
590
+
582
591
  specify("default value with interpolation", function(){
583
592
  actual = I18n.t(
584
- "alert",
593
+ "alert",
585
594
  {defaultValue: "Attention! {{message}}", message: "You're out of quota!"}
586
595
  );
587
-
596
+
588
597
  expect(actual).toBeEqualTo("Attention! You're out of quota!");
589
598
  });
590
-
599
+
591
600
  specify("default value should not be used when scope exist", function(){
592
601
  actual = I18n.t("hello", {defaultValue: "What's up?"});
593
602
  expect(actual).toBeEqualTo("Hello World!");
594
603
  });
595
-
604
+
596
605
  specify("default value for pluralize", function(){
597
606
  options = {defaultValue: {
598
607
  none: "No things here!",
599
608
  one: "There is {{count}} thing here!",
600
609
  other: "There are {{count}} things here!"
601
610
  }};
602
-
611
+
603
612
  expect(I18n.p(0, "things", options)).toBeEqualTo("No things here!");
604
613
  expect(I18n.p(1, "things", options)).toBeEqualTo("There is 1 thing here!");
605
614
  expect(I18n.p(5, "things", options)).toBeEqualTo("There are 5 things here!");
606
615
  });
607
-
616
+
608
617
  specify("default value for pluralize should not be used when scope exist", function(){
609
618
  options = {defaultValue: {
610
619
  none: "No things here!",
611
620
  one: "There is {{count}} thing here!",
612
621
  other: "There are {{count}} things here!"
613
622
  }};
614
-
623
+
615
624
  expect(I18n.pluralize(0, "inbox", options)).toBeEqualTo("You have no messages");
616
625
  expect(I18n.pluralize(1, "inbox", options)).toBeEqualTo("You have 1 message");
617
626
  expect(I18n.pluralize(5, "inbox", options)).toBeEqualTo("You have 5 messages");
618
627
  });
619
-
628
+
620
629
  specify("prepare options", function(){
621
630
  options = I18n.prepareOptions(
622
631
  {name: "Mary Doe"},
623
632
  {name: "John Doe", role: "user"}
624
633
  );
625
-
634
+
626
635
  expect(options["name"]).toBeEqualTo("Mary Doe");
627
636
  expect(options["role"]).toBeEqualTo("user");
628
637
  });
629
-
638
+
630
639
  specify("prepare options with multiple options", function(){
631
640
  options = I18n.prepareOptions(
632
641
  {name: "Mary Doe"},
@@ -635,27 +644,27 @@ describe("I18n.js", function(){
635
644
  {email: "mary@doe.com", url: "http://marydoe.com"},
636
645
  {role: "admin", email: "john@doe.com"}
637
646
  );
638
-
647
+
639
648
  expect(options["name"]).toBeEqualTo("Mary Doe");
640
649
  expect(options["role"]).toBeEqualTo("user");
641
650
  expect(options["age"]).toBeEqualTo(33);
642
651
  expect(options["email"]).toBeEqualTo("mary@doe.com");
643
652
  expect(options["url"]).toBeEqualTo("http://marydoe.com");
644
653
  });
645
-
654
+
646
655
  specify("prepare options should return an empty hash when values are null", function(){
647
656
  expect({}).toBeEqualTo(I18n.prepareOptions(null, null));
648
657
  });
649
-
658
+
650
659
  specify("percentage with defaults", function(){
651
660
  expect(I18n.toPercentage(1234)).toBeEqualTo("1234.000%");
652
661
  });
653
-
662
+
654
663
  specify("percentage with custom options", function(){
655
664
  actual = I18n.toPercentage(1234, {delimiter: "_", precision: 0});
656
665
  expect(actual).toBeEqualTo("1_234%");
657
666
  });
658
-
667
+
659
668
  specify("percentage with translation", function(){
660
669
  I18n.translations.en.number = {
661
670
  percentage: {
@@ -666,10 +675,10 @@ describe("I18n.js", function(){
666
675
  }
667
676
  }
668
677
  };
669
-
678
+
670
679
  expect(I18n.toPercentage(1234)).toBeEqualTo("1.234,00%");
671
680
  });
672
-
681
+
673
682
  specify("percentage with translation and custom options", function(){
674
683
  I18n.translations.en.number = {
675
684
  percentage: {
@@ -680,61 +689,61 @@ describe("I18n.js", function(){
680
689
  }
681
690
  }
682
691
  };
683
-
692
+
684
693
  actual = I18n.toPercentage(1234, {precision: 4, delimiter: "-", separator: "+"});
685
694
  expect(actual).toBeEqualTo("1-234+0000%");
686
695
  });
687
-
696
+
688
697
  specify("scope option as string", function(){
689
698
  actual = I18n.t("stranger", {scope: "greetings"});
690
699
  expect(actual).toBeEqualTo("Hello stranger!");
691
700
  });
692
-
701
+
693
702
  specify("scope as array", function(){
694
703
  actual = I18n.t(["greetings", "stranger"]);
695
704
  expect(actual).toBeEqualTo("Hello stranger!");
696
705
  });
697
-
706
+
698
707
  specify("new placeholder syntax", function(){
699
708
  I18n.translations["en"]["new_syntax"] = "Hi %{name}!";
700
709
  actual = I18n.t("new_syntax", {name: "John"});
701
710
  expect(actual).toBeEqualTo("Hi John!");
702
711
  });
703
-
712
+
704
713
  specify("return translation for custom scope separator", function(){
705
714
  I18n.defaultSeparator = "•";
706
715
  actual = I18n.t("greetings•stranger");
707
716
  expect(actual).toBeEqualTo("Hello stranger!");
708
717
  });
709
-
718
+
710
719
  specify("return number as human size", function(){
711
720
  kb = 1024;
712
-
721
+
713
722
  expect(I18n.toHumanSize(1)).toBeEqualTo("1Byte");
714
723
  expect(I18n.toHumanSize(100)).toBeEqualTo("100Bytes");
715
-
724
+
716
725
  expect(I18n.toHumanSize(kb)).toBeEqualTo("1KB");
717
726
  expect(I18n.toHumanSize(kb * 1.5)).toBeEqualTo("1.5KB");
718
-
727
+
719
728
  expect(I18n.toHumanSize(kb * kb)).toBeEqualTo("1MB");
720
729
  expect(I18n.toHumanSize(kb * kb * 1.5)).toBeEqualTo("1.5MB");
721
-
730
+
722
731
  expect(I18n.toHumanSize(kb * kb * kb)).toBeEqualTo("1GB");
723
732
  expect(I18n.toHumanSize(kb * kb * kb * 1.5)).toBeEqualTo("1.5GB");
724
-
733
+
725
734
  expect(I18n.toHumanSize(kb * kb * kb * kb)).toBeEqualTo("1TB");
726
735
  expect(I18n.toHumanSize(kb * kb * kb * kb * 1.5)).toBeEqualTo("1.5TB");
727
-
736
+
728
737
  expect(I18n.toHumanSize(kb * kb * kb * kb * kb)).toBeEqualTo("1024TB");
729
738
  });
730
-
739
+
731
740
  specify("return number as human size using custom options", function(){
732
741
  expect(I18n.toHumanSize(1024 * 1.6, {precision: 0})).toBeEqualTo("2KB");
733
742
  });
734
-
743
+
735
744
  specify("return number without insignificant zeros", function(){
736
745
  options = {precision: 4, strip_insignificant_zeros: true};
737
-
746
+
738
747
  expect(I18n.toNumber(65, options)).toBeEqualTo("65");
739
748
  expect(I18n.toNumber(1.2, options)).toBeEqualTo("1.2");
740
749
  expect(I18n.toCurrency(1.2, options)).toBeEqualTo("$1.2");