i18n-js 2.1.2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +23 -31
- data/README.md +318 -0
- data/Rakefile +6 -6
- data/app/assets/javascripts/i18n/translations.js.erb +3 -0
- data/i18n-js.gemspec +5 -6
- data/lib/i18n-js.rb +1 -177
- data/lib/i18n.js +698 -0
- data/lib/i18n/js.rb +157 -0
- data/lib/i18n/js/engine.rb +22 -0
- data/lib/{i18n-js → i18n/js}/middleware.rb +7 -7
- data/lib/i18n/js/version.rb +10 -0
- data/spec/{resources → fixtures}/custom_path.yml +1 -1
- data/spec/{resources → fixtures}/default.yml +1 -1
- data/spec/fixtures/js_file_per_locale.yml +3 -0
- data/spec/{resources → fixtures}/locales.yml +1 -1
- data/spec/fixtures/multiple_conditions.yml +5 -0
- data/spec/{resources → fixtures}/multiple_files.yml +3 -3
- data/spec/{resources → fixtures}/no_config.yml +0 -0
- data/spec/{resources → fixtures}/no_scope.yml +1 -1
- data/spec/{resources → fixtures}/simple_scope.yml +1 -1
- data/spec/i18n_js_spec.rb +122 -0
- data/spec/js/currency.spec.js +60 -0
- data/spec/js/current_locale.spec.js +19 -0
- data/spec/js/dates.spec.js +218 -0
- data/spec/js/defaults.spec.js +23 -0
- data/spec/js/interpolation.spec.js +28 -0
- data/spec/js/jasmine/MIT.LICENSE +20 -0
- data/spec/js/jasmine/jasmine-html.js +190 -0
- data/spec/js/jasmine/jasmine.css +166 -0
- data/spec/js/jasmine/jasmine.js +2476 -0
- data/spec/js/jasmine/jasmine_favicon.png +0 -0
- data/spec/js/localization.spec.js +41 -0
- data/spec/js/numbers.spec.js +124 -0
- data/spec/js/placeholder.spec.js +24 -0
- data/spec/js/pluralization.spec.js +105 -0
- data/spec/js/prepare_options.spec.js +41 -0
- data/spec/js/specs.html +46 -0
- data/spec/js/translate.spec.js +115 -0
- data/spec/js/translations.js +115 -0
- data/spec/spec_helper.rb +36 -14
- metadata +115 -69
- data/.gitignore +0 -5
- data/.rspec +0 -1
- data/README.rdoc +0 -305
- data/config/i18n-js.yml +0 -22
- data/lib/i18n-js/engine.rb +0 -62
- data/lib/i18n-js/railtie.rb +0 -13
- data/lib/i18n-js/rake.rb +0 -16
- data/lib/i18n-js/version.rb +0 -10
- data/spec/i18n_spec.js +0 -768
- data/spec/i18n_spec.rb +0 -205
- data/spec/resources/js_file_per_locale.yml +0 -3
- data/spec/resources/multiple_conditions.yml +0 -6
- data/vendor/assets/javascripts/i18n.js +0 -450
- data/vendor/assets/javascripts/i18n/translations.js.erb +0 -7
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color --format documentation
|
data/README.rdoc
DELETED
@@ -1,305 +0,0 @@
|
|
1
|
-
= I18n for JavaScript
|
2
|
-
|
3
|
-
It's a small library to provide the Rails I18n translations on the Javascript.
|
4
|
-
|
5
|
-
== Usage
|
6
|
-
|
7
|
-
=== Installation
|
8
|
-
|
9
|
-
gem install i18n-js
|
10
|
-
|
11
|
-
=== Setting up
|
12
|
-
|
13
|
-
You <b>don't</b> need to set up a thing. The default settings will work just okay. But if you want to split translations into several files or specify specific contexts, you can follow the rest of this setting up section.
|
14
|
-
|
15
|
-
==== Rails <= 3.0
|
16
|
-
|
17
|
-
Run <tt>rake i18n:js: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!
|
18
|
-
|
19
|
-
==== Rails >= 3.1
|
20
|
-
|
21
|
-
Add the following lines to your application.js to make the javascripts and translations available to your app:
|
22
|
-
|
23
|
-
//= require i18n
|
24
|
-
//= require i18n/translations
|
25
|
-
|
26
|
-
If asset pipeline has been disabled for your Rails application, then you will need to run <tt>rake i18n:js:setup</tt> to copy <tt>i18n-js.yml</tt> to your config folder (if not already present).
|
27
|
-
|
28
|
-
==== Exporting translations
|
29
|
-
|
30
|
-
You can export the translations file by running <tt>rake i18n:js:export</tt>.
|
31
|
-
Translations will be automatically exported in development mode.
|
32
|
-
|
33
|
-
==== Configuration
|
34
|
-
|
35
|
-
Translation files can be customized. You can even get more files generated to different folders and with different translations to best suit your needs.
|
36
|
-
|
37
|
-
Examples:
|
38
|
-
|
39
|
-
translations:
|
40
|
-
- file: 'public/javascripts/path-to-your-messages-file.js'
|
41
|
-
only: '*.date.formats'
|
42
|
-
- file: 'public/javascripts/path-to-your-second-file.js'
|
43
|
-
only: ['*.activerecord', '*.admin.*.title']
|
44
|
-
|
45
|
-
If <tt>only</tt> is omitted all the translations will be saved. Also, make sure you add that initial <tt>*</tt>; it specifies that all languages will be exported. If you want to export only one language, you can do something like this:
|
46
|
-
|
47
|
-
translations:
|
48
|
-
- file: 'public/javascripts/en.js'
|
49
|
-
only: 'en.*'
|
50
|
-
- file: 'public/javascripts/pt-BR.js'
|
51
|
-
only: 'pt-BR.*'
|
52
|
-
|
53
|
-
Optionaly, you can auto generate a translation file per available locale if you specify the <tt>%{locale}</tt> placeholder.
|
54
|
-
|
55
|
-
translations:
|
56
|
-
- file: "public/javascripts/i18n/%{locale}.js"
|
57
|
-
only: '*'
|
58
|
-
- file: "public/javascripts/frontend/i18n/%{locale}.js"
|
59
|
-
only: ['frontend', 'users']
|
60
|
-
|
61
|
-
To find more examples on how to use the configuration file please refer to the tests.
|
62
|
-
|
63
|
-
=== On the Javascript
|
64
|
-
|
65
|
-
Set your locale is easy as
|
66
|
-
|
67
|
-
I18n.defaultLocale = "pt-BR";
|
68
|
-
I18n.locale = "pt-BR";
|
69
|
-
I18n.currentLocale();
|
70
|
-
// pt-BR
|
71
|
-
|
72
|
-
In practice, you'll have something like the following in your <tt>application.html.erb</tt>:
|
73
|
-
|
74
|
-
<script type="text/javascript">
|
75
|
-
I18n.defaultLocale = "<%= I18n.default_locale %>";
|
76
|
-
I18n.locale = "<%= I18n.locale %>";
|
77
|
-
</script>
|
78
|
-
|
79
|
-
You can use translate your messages:
|
80
|
-
|
81
|
-
I18n.t("some.scoped.translation");
|
82
|
-
// or translate with explicite setting of locale
|
83
|
-
I18n.t("some.scoped.translation", {locale: "fr"});
|
84
|
-
|
85
|
-
You can also interpolate values:
|
86
|
-
|
87
|
-
I18n.t("hello", {name: "John Doe"});
|
88
|
-
|
89
|
-
The sample above will assume that you have the following translations in your
|
90
|
-
<tt>config/locales/*.yml</tt>:
|
91
|
-
|
92
|
-
en:
|
93
|
-
hello: "Hello {{name}}!"
|
94
|
-
|
95
|
-
You can set default values for missing scopes:
|
96
|
-
|
97
|
-
// simple translation
|
98
|
-
I18n.t("some.missing.scope", {defaultValue: "A default message"});
|
99
|
-
|
100
|
-
// with interpolation
|
101
|
-
I18n.t("noun", {defaultValue: "I'm a {{noun}}", noun: "Mac"});
|
102
|
-
|
103
|
-
Translation fallback can be handled by taking from I18n.defaultLocale.
|
104
|
-
To allow this in your application.html.erb specify:
|
105
|
-
|
106
|
-
<script type="text/javascript">
|
107
|
-
I18n.fallbacks = true;
|
108
|
-
</script>
|
109
|
-
|
110
|
-
Then missing translation will be taken from your I18n.defaultLocale.
|
111
|
-
Example:
|
112
|
-
// if I18n.defaultLocale = "en" and translation doesn't exist for I18n.locale = "de"
|
113
|
-
I18n.t("some.missing.scope");
|
114
|
-
// this key will be taken from "en" locale scope
|
115
|
-
|
116
|
-
Pluralization is possible as well:
|
117
|
-
|
118
|
-
I18n.t("inbox.counting", {count: 10}); // You have 10 messages
|
119
|
-
|
120
|
-
The sample above expects the following translation:
|
121
|
-
|
122
|
-
en:
|
123
|
-
inbox:
|
124
|
-
counting:
|
125
|
-
one: You have 1 new message
|
126
|
-
other: You have {{count}} new messages
|
127
|
-
zero: You have no messages
|
128
|
-
|
129
|
-
<b>NOTE:</b> Rais I18n recognizes the +zero+ option.
|
130
|
-
|
131
|
-
If you're using the same scope over and over again, you may use the +scope+ option.
|
132
|
-
|
133
|
-
var options = {scope: "activerecord.attributes.user"};
|
134
|
-
|
135
|
-
I18n.t("name", options);
|
136
|
-
I18n.t("email", options);
|
137
|
-
I18n.t("username", options);
|
138
|
-
|
139
|
-
You also provide an array as scope.
|
140
|
-
|
141
|
-
// use the greetings.hello scope
|
142
|
-
I18n.t(["greetings", "hello"]);
|
143
|
-
|
144
|
-
==== Number formatting
|
145
|
-
|
146
|
-
Similar to Rails helpers, you have localized number and currency formatting.
|
147
|
-
|
148
|
-
I18n.l("currency", 1990.99);
|
149
|
-
// $1,990.99
|
150
|
-
|
151
|
-
I18n.l("number", 1990.99);
|
152
|
-
// 1,990.99
|
153
|
-
|
154
|
-
I18n.l("percentage", 123.45);
|
155
|
-
// 123.450%
|
156
|
-
|
157
|
-
To have more control over number formatting, you can use the <tt>I18n.toNumber</tt>, <tt>I18n.toPercentage</tt>, <tt>I18n.toCurrency</tt> and <tt>I18n.toHumanSize</tt> functions.
|
158
|
-
|
159
|
-
I18n.toNumber(1000); // 1,000.000
|
160
|
-
I18n.toCurrency(1000); // $1,000.00
|
161
|
-
I18n.toPercentage(100); // 100.000%
|
162
|
-
|
163
|
-
The +toNumber+ and +toPercentage+ functions accept the following options:
|
164
|
-
|
165
|
-
* +precision+: defaults to 3
|
166
|
-
* +separator+: defaults to <tt>.</tt>
|
167
|
-
* +delimiter+: defaults to <tt>,</tt>
|
168
|
-
* +strip_insignificant_zeros+: defaults to <tt>false</tt>
|
169
|
-
|
170
|
-
See some number formatting examples:
|
171
|
-
|
172
|
-
I18n.toNumber(1000, {precision: 0}); // 1,000
|
173
|
-
I18n.toNumber(1000, {delimiter: ".", separator: ","}); // 1.000,000
|
174
|
-
I18n.toNumber(1000, {delimiter: ".", precision: 0}); // 1.000
|
175
|
-
|
176
|
-
The +toCurrency+ function accepts the following options:
|
177
|
-
|
178
|
-
* +precision+: sets the level of precision
|
179
|
-
* +separator+: sets the separator between the units
|
180
|
-
* +delimiter+: sets the thousands delimiter
|
181
|
-
* +format+: sets the format of the output string
|
182
|
-
* +unit+: sets the denomination of the currency
|
183
|
-
* +strip_insignificant_zeros+: defaults to <tt>false</tt>
|
184
|
-
|
185
|
-
You can provide only the options you want to override:
|
186
|
-
|
187
|
-
I18n.toCurrency(1000, {precision: 0}); // $1,000
|
188
|
-
|
189
|
-
The +toHumanSize+ function accepts the following options:
|
190
|
-
|
191
|
-
* +precision+: defaults to 1
|
192
|
-
* +separator+: defaults to <tt>.</tt>
|
193
|
-
* +delimiter+: defaults to <tt>""</tt>
|
194
|
-
* +strip_insignificant_zeros+: defaults to <tt>false</tt>
|
195
|
-
* +format+: defaults to <tt>%n%u</tt>
|
196
|
-
|
197
|
-
I18n.toHumanSize(1234); // 1KB
|
198
|
-
I18n.toHumanSize(1234 * 1024); // 1MB
|
199
|
-
|
200
|
-
==== Date formatting
|
201
|
-
|
202
|
-
// accepted formats
|
203
|
-
I18n.l("date.formats.short", "2009-09-18"); // yyyy-mm-dd
|
204
|
-
I18n.l("time.formats.short", "2009-09-18 23:12:43"); // yyyy-mm-dd hh:mm:ss
|
205
|
-
I18n.l("time.formats.short", "2009-11-09T18:10:34"); // JSON format with local Timezone (part of ISO-8601)
|
206
|
-
I18n.l("time.formats.short", "2009-11-09T18:10:34Z"); // JSON format in UTC (part of ISO-8601)
|
207
|
-
I18n.l("date.formats.short", 1251862029000); // Epoch time
|
208
|
-
I18n.l("date.formats.short", "09/18/2009"); // mm/dd/yyyy
|
209
|
-
I18n.l("date.formats.short", (new Date())); // Date object
|
210
|
-
|
211
|
-
If you prefer, you can use the <tt>I18n.strftime</tt> function to format dates.
|
212
|
-
|
213
|
-
var date = new Date();
|
214
|
-
I18n.strftime(date, "%d/%m/%Y");
|
215
|
-
|
216
|
-
The accepted formats are:
|
217
|
-
|
218
|
-
%a - The abbreviated weekday name (Sun)
|
219
|
-
%A - The full weekday name (Sunday)
|
220
|
-
%b - The abbreviated month name (Jan)
|
221
|
-
%B - The full month name (January)
|
222
|
-
%c - The preferred local date and time representation
|
223
|
-
%d - Day of the month (01..31)
|
224
|
-
%-d - Day of the month (1..31)
|
225
|
-
%H - Hour of the day, 24-hour clock (00..23)
|
226
|
-
%-H - Hour of the day, 24-hour clock (0..23)
|
227
|
-
%I - Hour of the day, 12-hour clock (01..12)
|
228
|
-
%-I - Hour of the day, 12-hour clock (1..12)
|
229
|
-
%m - Month of the year (01..12)
|
230
|
-
%-m - Month of the year (1..12)
|
231
|
-
%M - Minute of the hour (00..59)
|
232
|
-
%-M - Minute of the hour (0..59)
|
233
|
-
%p - Meridian indicator (AM or PM)
|
234
|
-
%S - Second of the minute (00..60)
|
235
|
-
%-S - Second of the minute (0..60)
|
236
|
-
%w - Day of the week (Sunday is 0, 0..6)
|
237
|
-
%y - Year without a century (00..99)
|
238
|
-
%-y - Year without a century (0..99)
|
239
|
-
%Y - Year with century
|
240
|
-
%z - Timezone offset (+0545)
|
241
|
-
|
242
|
-
Check out <tt>vendor/plugins/i18n-js/spec/i18n_spec.js</tt> for more examples!
|
243
|
-
|
244
|
-
== Using I18nJS with other languages (Python, PHP, ...)
|
245
|
-
|
246
|
-
The JavaScript library is language agnostic; so you can use it with PHP, Python, [you favorite language here].
|
247
|
-
The only requirement is that you need to set the +translations+ attribute like following:
|
248
|
-
|
249
|
-
I18n.translations = {};
|
250
|
-
|
251
|
-
I18n.translations["en"] = {
|
252
|
-
message: "Some special message for you"
|
253
|
-
}
|
254
|
-
|
255
|
-
I18n.translations["pt-BR"] = {
|
256
|
-
message: "Uma mensagem especial para você"
|
257
|
-
}
|
258
|
-
|
259
|
-
== Maintainer
|
260
|
-
|
261
|
-
* Nando Vieira - http://simplesideias.com.br
|
262
|
-
* Sébastien Grosjean - http://github.com/ZenCocoon
|
263
|
-
|
264
|
-
== Contributing
|
265
|
-
|
266
|
-
Once you've made your great commits:
|
267
|
-
|
268
|
-
1. Fork[http://help.github.com/forking/] I18n-JS
|
269
|
-
2. Create a topic branch - <tt>git checkout -b my_branch</tt>
|
270
|
-
3. Push to your branch - <tt>git push origin my_branch</tt>
|
271
|
-
4. Create an Issue[http://github.com/fnando/i18n-js/issues] with a link to your branch
|
272
|
-
5. That's it!
|
273
|
-
|
274
|
-
Please respect the indentation rules. And use 2 spaces, not tabs.
|
275
|
-
|
276
|
-
=== Running tests
|
277
|
-
|
278
|
-
First, install all dependencies.
|
279
|
-
|
280
|
-
bundle install
|
281
|
-
|
282
|
-
Then just run <tt>rake spec</tt>.
|
283
|
-
|
284
|
-
== License
|
285
|
-
|
286
|
-
(The MIT License)
|
287
|
-
|
288
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
289
|
-
a copy of this software and associated documentation files (the
|
290
|
-
'Software'), to deal in the Software without restriction, including
|
291
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
292
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
293
|
-
permit persons to whom the Software is furnished to do so, subject to
|
294
|
-
the following conditions:
|
295
|
-
|
296
|
-
The above copyright notice and this permission notice shall be
|
297
|
-
included in all copies or substantial portions of the Software.
|
298
|
-
|
299
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
300
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
301
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
302
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
303
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
304
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
305
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/config/i18n-js.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# Split context in several files.
|
2
|
-
# By default only one file with all translations is exported and
|
3
|
-
# no configuration is required. Your settings for asset pipeline
|
4
|
-
# are automatically recognized.
|
5
|
-
#
|
6
|
-
# If you want to split translations into several files or specify
|
7
|
-
# locale contexts that will be exported, just use this file to do
|
8
|
-
# so.
|
9
|
-
#
|
10
|
-
# If you're going to use the Rails 3.1 asset pipeline, change
|
11
|
-
# the following configuration to something like this:
|
12
|
-
#
|
13
|
-
# translations:
|
14
|
-
# - file: "app/assets/javascripts/i18n/translations.js"
|
15
|
-
#
|
16
|
-
# If you're running an old version, you can use something
|
17
|
-
# like this:
|
18
|
-
#
|
19
|
-
# translations:
|
20
|
-
# - file: "public/javascripts/translations.js"
|
21
|
-
# only: "*"
|
22
|
-
#
|
data/lib/i18n-js/engine.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
module SimplesIdeias
|
2
|
-
module I18n
|
3
|
-
class Engine < ::Rails::Engine
|
4
|
-
I18N_TRANSLATIONS_ASSET = "i18n/translations"
|
5
|
-
|
6
|
-
initializer "i18n-js.asset_dependencies", :after => "sprockets.environment" do
|
7
|
-
next unless SimplesIdeias::I18n.has_asset_pipeline?
|
8
|
-
|
9
|
-
config = Rails.root.join("config", "i18n-js.yml")
|
10
|
-
cache_file = I18n::Engine.load_path_hash_cache
|
11
|
-
|
12
|
-
Rails.application.assets.register_preprocessor "application/javascript", :"i18n-js_dependencies" do |context, data|
|
13
|
-
if context.logical_path == I18N_TRANSLATIONS_ASSET
|
14
|
-
context.depend_on(config)
|
15
|
-
# also set up dependencies on every locale file
|
16
|
-
::I18n.load_path.each {|path| context.depend_on(path)}
|
17
|
-
|
18
|
-
# Set up a dependency on the contents of the load path
|
19
|
-
# itself. In some situations it is possible to get here
|
20
|
-
# before the path hash cache file has been written; in
|
21
|
-
# this situation, write it now.
|
22
|
-
I18n::Engine.write_hash! unless File.exists?(cache_file)
|
23
|
-
context.depend_on(cache_file)
|
24
|
-
end
|
25
|
-
|
26
|
-
data
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# rewrite path cache hash at startup and before each request in development
|
31
|
-
config.to_prepare do
|
32
|
-
next unless SimplesIdeias::I18n.has_asset_pipeline?
|
33
|
-
SimplesIdeias::I18n::Engine.write_hash_if_changed unless Rails.env.production?
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.load_path_hash_cache
|
37
|
-
@load_path_hash_cache ||= Rails.root.join("tmp/i18n-js.cache")
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.write_hash_if_changed
|
41
|
-
load_path_hash = ::I18n.load_path.hash
|
42
|
-
|
43
|
-
if load_path_hash != cached_load_path_hash
|
44
|
-
self.cached_load_path_hash = load_path_hash
|
45
|
-
write_hash!
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.write_hash!
|
50
|
-
FileUtils.mkdir_p Rails.root.join("tmp")
|
51
|
-
|
52
|
-
File.open(load_path_hash_cache, "w+") do |f|
|
53
|
-
f.write(cached_load_path_hash)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class << self
|
58
|
-
attr_accessor :cached_load_path_hash
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/lib/i18n-js/railtie.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module SimplesIdeias
|
2
|
-
module I18n
|
3
|
-
class Railtie < Rails::Railtie
|
4
|
-
rake_tasks do
|
5
|
-
require "i18n-js/rake"
|
6
|
-
end
|
7
|
-
|
8
|
-
initializer "i18n-js.initialize" do |app|
|
9
|
-
app.config.middleware.use(Middleware) if Rails.env.development? && !SimplesIdeias::I18n.has_asset_pipeline?
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/i18n-js/rake.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
namespace "i18n:js" do
|
2
|
-
desc "Copy i18n.js and configuration file"
|
3
|
-
task :setup => :environment do
|
4
|
-
SimplesIdeias::I18n.setup!
|
5
|
-
end
|
6
|
-
|
7
|
-
desc "Export the messages files"
|
8
|
-
task :export => :environment do
|
9
|
-
SimplesIdeias::I18n.export!
|
10
|
-
end
|
11
|
-
|
12
|
-
desc "Update the JavaScript library"
|
13
|
-
task :update => :environment do
|
14
|
-
SimplesIdeias::I18n.update!
|
15
|
-
end
|
16
|
-
end
|
data/lib/i18n-js/version.rb
DELETED
data/spec/i18n_spec.js
DELETED
@@ -1,768 +0,0 @@
|
|
1
|
-
load("vendor/assets/javascripts/i18n.js");
|
2
|
-
|
3
|
-
describe("I18n.js", function(){
|
4
|
-
before(function() {
|
5
|
-
I18n.defaultLocale = "en";
|
6
|
-
I18n.defaultSeparator = ".";
|
7
|
-
I18n.locale = null;
|
8
|
-
|
9
|
-
I18n.translations = {
|
10
|
-
en: {
|
11
|
-
hello: "Hello World!",
|
12
|
-
greetings: {
|
13
|
-
stranger: "Hello stranger!",
|
14
|
-
name: "Hello {{name}}!"
|
15
|
-
},
|
16
|
-
profile: {
|
17
|
-
details: "{{name}} is {{age}}-years old"
|
18
|
-
},
|
19
|
-
inbox: {
|
20
|
-
one: "You have {{count}} message",
|
21
|
-
other: "You have {{count}} messages",
|
22
|
-
zero: "You have no messages"
|
23
|
-
},
|
24
|
-
unread: {
|
25
|
-
one: "You have 1 new message ({{unread}} unread)",
|
26
|
-
other: "You have {{count}} new messages ({{unread}} unread)",
|
27
|
-
zero: "You have no new messages ({{unread}} unread)"
|
28
|
-
},
|
29
|
-
number: {
|
30
|
-
human: {
|
31
|
-
storage_units: {
|
32
|
-
units: {
|
33
|
-
"byte": {
|
34
|
-
one: "Byte",
|
35
|
-
other: "Bytes"
|
36
|
-
},
|
37
|
-
|
38
|
-
"kb": "KB",
|
39
|
-
"mb": "MB",
|
40
|
-
"gb": "GB",
|
41
|
-
"tb": "TB"
|
42
|
-
}
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
},
|
47
|
-
|
48
|
-
"pt-BR": {
|
49
|
-
hello: "Olá Mundo!",
|
50
|
-
date: {
|
51
|
-
formats: {
|
52
|
-
"default": "%d/%m/%Y",
|
53
|
-
"short": "%d de %B",
|
54
|
-
"long": "%d de %B de %Y"
|
55
|
-
},
|
56
|
-
day_names: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"],
|
57
|
-
abbr_day_names: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
|
58
|
-
month_names: [null, "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
|
59
|
-
abbr_month_names: [null, "Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
|
60
|
-
},
|
61
|
-
number: {
|
62
|
-
percentage: {
|
63
|
-
format: {
|
64
|
-
delimiter: "",
|
65
|
-
separator: ",",
|
66
|
-
precision: 2
|
67
|
-
}
|
68
|
-
}
|
69
|
-
},
|
70
|
-
time: {
|
71
|
-
formats: {
|
72
|
-
"default": "%A, %d de %B de %Y, %H:%M h",
|
73
|
-
"short": "%d/%m, %H:%M h",
|
74
|
-
"long": "%A, %d de %B de %Y, %H:%M h"
|
75
|
-
},
|
76
|
-
am: "AM",
|
77
|
-
pm: "PM"
|
78
|
-
}
|
79
|
-
},
|
80
|
-
|
81
|
-
"en-US": {
|
82
|
-
date: {
|
83
|
-
formats: {
|
84
|
-
"default": "%d/%m/%Y",
|
85
|
-
"short": "%d de %B",
|
86
|
-
"long": "%d de %B de %Y"
|
87
|
-
},
|
88
|
-
day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
89
|
-
abbr_day_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
90
|
-
month_names: [null, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
91
|
-
abbr_month_names: [null, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"],
|
92
|
-
meridian: ["am", "pm"]
|
93
|
-
}
|
94
|
-
}
|
95
|
-
};
|
96
|
-
});
|
97
|
-
|
98
|
-
specify("with default options", function(){
|
99
|
-
expect(I18n.defaultLocale).toBeEqualTo("en");
|
100
|
-
expect(I18n.locale).toBeEqualTo(null);
|
101
|
-
expect(I18n.currentLocale()).toBeEqualTo("en");
|
102
|
-
});
|
103
|
-
|
104
|
-
specify("with custom locale", function(){
|
105
|
-
I18n.locale = "pt-BR";
|
106
|
-
expect(I18n.currentLocale()).toBeEqualTo("pt-BR");
|
107
|
-
});
|
108
|
-
|
109
|
-
specify("aliases", function(){
|
110
|
-
expect(I18n.t).toBe(I18n.translate);
|
111
|
-
expect(I18n.l).toBe(I18n.localize);
|
112
|
-
expect(I18n.p).toBe(I18n.pluralize);
|
113
|
-
});
|
114
|
-
|
115
|
-
specify("translation with single scope", function(){
|
116
|
-
expect(I18n.t("hello")).toBeEqualTo("Hello World!");
|
117
|
-
});
|
118
|
-
|
119
|
-
specify("translation as object", function(){
|
120
|
-
expect(I18n.t("greetings")).toBeInstanceOf(Object);
|
121
|
-
});
|
122
|
-
|
123
|
-
specify("translation with invalid scope shall not block", function(){
|
124
|
-
actual = I18n.t("invalid.scope.shall.not.block");
|
125
|
-
expected = '[missing "en.invalid.scope.shall.not.block" translation]';
|
126
|
-
expect(actual).toBeEqualTo(expected);
|
127
|
-
});
|
128
|
-
|
129
|
-
specify("translation for single scope on a custom locale", function(){
|
130
|
-
I18n.locale = "pt-BR";
|
131
|
-
expect(I18n.t("hello")).toBeEqualTo("Olá Mundo!");
|
132
|
-
});
|
133
|
-
|
134
|
-
specify("translation for multiple scopes", function(){
|
135
|
-
expect(I18n.t("greetings.stranger")).toBeEqualTo("Hello stranger!");
|
136
|
-
});
|
137
|
-
|
138
|
-
specify("translation with default locale option", function(){
|
139
|
-
expect(I18n.t("hello", {locale: "en"})).toBeEqualTo("Hello World!");
|
140
|
-
expect(I18n.t("hello", {locale: "pt-BR"})).toBeEqualTo("Olá Mundo!");
|
141
|
-
});
|
142
|
-
|
143
|
-
specify("translation should fall if locale is missing", function(){
|
144
|
-
I18n.locale = "pt-BR";
|
145
|
-
expect(I18n.t("greetings.stranger")).toBeEqualTo("[missing \"pt-BR.greetings.stranger\" translation]");
|
146
|
-
});
|
147
|
-
|
148
|
-
specify("translation should handle fallback if I18n.fallbacks == true", function(){
|
149
|
-
I18n.locale = "pt-BR";
|
150
|
-
I18n.fallbacks = true;
|
151
|
-
expect(I18n.t("greetings.stranger")).toBeEqualTo("Hello stranger!");
|
152
|
-
});
|
153
|
-
|
154
|
-
specify("single interpolation", function(){
|
155
|
-
actual = I18n.t("greetings.name", {name: "John Doe"});
|
156
|
-
expect(actual).toBeEqualTo("Hello John Doe!");
|
157
|
-
});
|
158
|
-
|
159
|
-
specify("multiple interpolation", function(){
|
160
|
-
actual = I18n.t("profile.details", {name: "John Doe", age: 27});
|
161
|
-
expect(actual).toBeEqualTo("John Doe is 27-years old");
|
162
|
-
});
|
163
|
-
|
164
|
-
specify("translation with count option", function(){
|
165
|
-
expect(I18n.t("inbox", {count: 0})).toBeEqualTo("You have no messages");
|
166
|
-
expect(I18n.t("inbox", {count: 1})).toBeEqualTo("You have 1 message");
|
167
|
-
expect(I18n.t("inbox", {count: 5})).toBeEqualTo("You have 5 messages");
|
168
|
-
});
|
169
|
-
|
170
|
-
specify("translation with count option and multiple placeholders", function(){
|
171
|
-
actual = I18n.t("unread", {unread: 5, count: 1});
|
172
|
-
expect(actual).toBeEqualTo("You have 1 new message (5 unread)");
|
173
|
-
|
174
|
-
actual = I18n.t("unread", {unread: 2, count: 10});
|
175
|
-
expect(actual).toBeEqualTo("You have 10 new messages (2 unread)");
|
176
|
-
|
177
|
-
actual = I18n.t("unread", {unread: 5, count: 0});
|
178
|
-
expect(actual).toBeEqualTo("You have no new messages (5 unread)");
|
179
|
-
});
|
180
|
-
|
181
|
-
specify("missing translation with count option", function(){
|
182
|
-
actual = I18n.t("invalid", {count: 1});
|
183
|
-
expect(actual).toBeEqualTo('[missing "en.invalid" translation]');
|
184
|
-
|
185
|
-
I18n.translations.en.inbox.one = null;
|
186
|
-
actual = I18n.t("inbox", {count: 1});
|
187
|
-
expect(actual).toBeEqualTo('[missing "en.inbox.one" translation]');
|
188
|
-
});
|
189
|
-
|
190
|
-
specify("pluralization", function(){
|
191
|
-
expect(I18n.p(0, "inbox")).toBeEqualTo("You have no messages");
|
192
|
-
expect(I18n.p(1, "inbox")).toBeEqualTo("You have 1 message");
|
193
|
-
expect(I18n.p(5, "inbox")).toBeEqualTo("You have 5 messages");
|
194
|
-
});
|
195
|
-
|
196
|
-
specify("pluralize should return 'other' scope", function(){
|
197
|
-
I18n.translations["en"]["inbox"]["zero"] = null;
|
198
|
-
expect(I18n.p(0, "inbox")).toBeEqualTo("You have 0 messages");
|
199
|
-
});
|
200
|
-
|
201
|
-
specify("pluralize should return 'zero' scope", function(){
|
202
|
-
I18n.translations["en"]["inbox"]["zero"] = "No messages (zero)";
|
203
|
-
I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
|
204
|
-
|
205
|
-
expect(I18n.p(0, "inbox")).toBeEqualTo("No messages (zero)");
|
206
|
-
});
|
207
|
-
|
208
|
-
specify("pluralize should return 'none' scope", function(){
|
209
|
-
I18n.translations["en"]["inbox"]["zero"] = null;
|
210
|
-
I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
|
211
|
-
|
212
|
-
expect(I18n.p(0, "inbox")).toBeEqualTo("No messages (none)");
|
213
|
-
});
|
214
|
-
|
215
|
-
specify("pluralize with negative values", function(){
|
216
|
-
expect(I18n.p(-1, "inbox")).toBeEqualTo("You have -1 message");
|
217
|
-
expect(I18n.p(-5, "inbox")).toBeEqualTo("You have -5 messages");
|
218
|
-
});
|
219
|
-
|
220
|
-
specify("pluralize with missing scope", function(){
|
221
|
-
expect(I18n.p(-1, "missing")).toBeEqualTo('[missing "en.missing" translation]');
|
222
|
-
});
|
223
|
-
|
224
|
-
specify("pluralize with multiple placeholders", function(){
|
225
|
-
actual = I18n.p(1, "unread", {unread: 5});
|
226
|
-
expect(actual).toBeEqualTo("You have 1 new message (5 unread)");
|
227
|
-
|
228
|
-
actual = I18n.p(10, "unread", {unread: 2});
|
229
|
-
expect(actual).toBeEqualTo("You have 10 new messages (2 unread)");
|
230
|
-
|
231
|
-
actual = I18n.p(0, "unread", {unread: 5});
|
232
|
-
expect(actual).toBeEqualTo("You have no new messages (5 unread)");
|
233
|
-
});
|
234
|
-
|
235
|
-
specify("pluralize should allow empty strings", function(){
|
236
|
-
I18n.translations["en"]["inbox"]["zero"] = "";
|
237
|
-
|
238
|
-
expect(I18n.p(0, "inbox")).toBeEqualTo("");
|
239
|
-
});
|
240
|
-
|
241
|
-
specify("numbers with default settings", function(){
|
242
|
-
expect(I18n.toNumber(1)).toBeEqualTo("1.000");
|
243
|
-
expect(I18n.toNumber(12)).toBeEqualTo("12.000");
|
244
|
-
expect(I18n.toNumber(123)).toBeEqualTo("123.000");
|
245
|
-
expect(I18n.toNumber(1234)).toBeEqualTo("1,234.000");
|
246
|
-
expect(I18n.toNumber(12345)).toBeEqualTo("12,345.000");
|
247
|
-
expect(I18n.toNumber(123456)).toBeEqualTo("123,456.000");
|
248
|
-
expect(I18n.toNumber(1234567)).toBeEqualTo("1,234,567.000");
|
249
|
-
expect(I18n.toNumber(12345678)).toBeEqualTo("12,345,678.000");
|
250
|
-
expect(I18n.toNumber(123456789)).toBeEqualTo("123,456,789.000");
|
251
|
-
});
|
252
|
-
|
253
|
-
specify("negative numbers with default settings", function(){
|
254
|
-
expect(I18n.toNumber(-1)).toBeEqualTo("-1.000");
|
255
|
-
expect(I18n.toNumber(-12)).toBeEqualTo("-12.000");
|
256
|
-
expect(I18n.toNumber(-123)).toBeEqualTo("-123.000");
|
257
|
-
expect(I18n.toNumber(-1234)).toBeEqualTo("-1,234.000");
|
258
|
-
expect(I18n.toNumber(-12345)).toBeEqualTo("-12,345.000");
|
259
|
-
expect(I18n.toNumber(-123456)).toBeEqualTo("-123,456.000");
|
260
|
-
expect(I18n.toNumber(-1234567)).toBeEqualTo("-1,234,567.000");
|
261
|
-
expect(I18n.toNumber(-12345678)).toBeEqualTo("-12,345,678.000");
|
262
|
-
expect(I18n.toNumber(-123456789)).toBeEqualTo("-123,456,789.000");
|
263
|
-
});
|
264
|
-
|
265
|
-
specify("numbers with partial translation and default options", function(){
|
266
|
-
I18n.translations.en.number = {
|
267
|
-
format: {
|
268
|
-
precision: 2
|
269
|
-
}
|
270
|
-
};
|
271
|
-
|
272
|
-
expect(I18n.toNumber(1234)).toBeEqualTo("1,234.00");
|
273
|
-
});
|
274
|
-
|
275
|
-
specify("numbers with full translation and default options", function(){
|
276
|
-
I18n.translations.en.number = {
|
277
|
-
format: {
|
278
|
-
delimiter: ".",
|
279
|
-
separator: ",",
|
280
|
-
precision: 2
|
281
|
-
}
|
282
|
-
};
|
283
|
-
|
284
|
-
expect(I18n.toNumber(1234)).toBeEqualTo("1.234,00");
|
285
|
-
});
|
286
|
-
|
287
|
-
specify("numbers with some custom options that should be merged with default options", function(){
|
288
|
-
expect(I18n.toNumber(1234, {precision: 0})).toBeEqualTo("1,234");
|
289
|
-
expect(I18n.toNumber(1234, {separator: '-'})).toBeEqualTo("1,234-000");
|
290
|
-
expect(I18n.toNumber(1234, {delimiter: '-'})).toBeEqualTo("1-234.000");
|
291
|
-
});
|
292
|
-
|
293
|
-
specify("numbers considering options", function(){
|
294
|
-
options = {
|
295
|
-
precision: 2,
|
296
|
-
separator: ",",
|
297
|
-
delimiter: "."
|
298
|
-
};
|
299
|
-
|
300
|
-
expect(I18n.toNumber(1, options)).toBeEqualTo("1,00");
|
301
|
-
expect(I18n.toNumber(12, options)).toBeEqualTo("12,00");
|
302
|
-
expect(I18n.toNumber(123, options)).toBeEqualTo("123,00");
|
303
|
-
expect(I18n.toNumber(1234, options)).toBeEqualTo("1.234,00");
|
304
|
-
expect(I18n.toNumber(123456, options)).toBeEqualTo("123.456,00");
|
305
|
-
expect(I18n.toNumber(1234567, options)).toBeEqualTo("1.234.567,00");
|
306
|
-
expect(I18n.toNumber(12345678, options)).toBeEqualTo("12.345.678,00");
|
307
|
-
});
|
308
|
-
|
309
|
-
specify("numbers with different precisions", function(){
|
310
|
-
options = {separator: ".", delimiter: ","};
|
311
|
-
|
312
|
-
options["precision"] = 2;
|
313
|
-
expect(I18n.toNumber(1.98, options)).toBeEqualTo("1.98");
|
314
|
-
|
315
|
-
options["precision"] = 3;
|
316
|
-
expect(I18n.toNumber(1.98, options)).toBeEqualTo("1.980");
|
317
|
-
|
318
|
-
options["precision"] = 2;
|
319
|
-
expect(I18n.toNumber(1.987, options)).toBeEqualTo("1.99");
|
320
|
-
|
321
|
-
options["precision"] = 1;
|
322
|
-
expect(I18n.toNumber(1.98, options)).toBeEqualTo("2.0");
|
323
|
-
|
324
|
-
options["precision"] = 0;
|
325
|
-
expect(I18n.toNumber(1.98, options)).toBeEqualTo("2");
|
326
|
-
});
|
327
|
-
|
328
|
-
specify("currency with default settings", function(){
|
329
|
-
expect(I18n.toCurrency(100.99)).toBeEqualTo("$100.99");
|
330
|
-
expect(I18n.toCurrency(1000.99)).toBeEqualTo("$1,000.99");
|
331
|
-
});
|
332
|
-
|
333
|
-
specify("currency with custom settings", function(){
|
334
|
-
I18n.translations.en.number = {
|
335
|
-
currency: {
|
336
|
-
format: {
|
337
|
-
format: "%n %u",
|
338
|
-
unit: "USD",
|
339
|
-
delimiter: ".",
|
340
|
-
separator: ",",
|
341
|
-
precision: 2
|
342
|
-
}
|
343
|
-
}
|
344
|
-
};
|
345
|
-
|
346
|
-
expect(I18n.toCurrency(12)).toBeEqualTo("12,00 USD");
|
347
|
-
expect(I18n.toCurrency(123)).toBeEqualTo("123,00 USD");
|
348
|
-
expect(I18n.toCurrency(1234.56)).toBeEqualTo("1.234,56 USD");
|
349
|
-
});
|
350
|
-
|
351
|
-
specify("currency with custom settings and partial overriding", function(){
|
352
|
-
I18n.translations.en.number = {
|
353
|
-
currency: {
|
354
|
-
format: {
|
355
|
-
format: "%n %u",
|
356
|
-
unit: "USD",
|
357
|
-
delimiter: ".",
|
358
|
-
separator: ",",
|
359
|
-
precision: 2
|
360
|
-
}
|
361
|
-
}
|
362
|
-
};
|
363
|
-
|
364
|
-
expect(I18n.toCurrency(12, {precision: 0})).toBeEqualTo("12 USD");
|
365
|
-
expect(I18n.toCurrency(123, {unit: "bucks"})).toBeEqualTo("123,00 bucks");
|
366
|
-
});
|
367
|
-
|
368
|
-
specify("currency with some custom options that should be merged with default options", function(){
|
369
|
-
expect(I18n.toCurrency(1234, {precision: 0})).toBeEqualTo("$1,234");
|
370
|
-
expect(I18n.toCurrency(1234, {unit: "º"})).toBeEqualTo("º1,234.00");
|
371
|
-
expect(I18n.toCurrency(1234, {separator: "-"})).toBeEqualTo("$1,234-00");
|
372
|
-
expect(I18n.toCurrency(1234, {delimiter: "-"})).toBeEqualTo("$1-234.00");
|
373
|
-
expect(I18n.toCurrency(1234, {format: "%u %n"})).toBeEqualTo("$ 1,234.00");
|
374
|
-
});
|
375
|
-
|
376
|
-
specify("localize numbers", function(){
|
377
|
-
expect(I18n.l("number", 1234567)).toBeEqualTo("1,234,567.000");
|
378
|
-
});
|
379
|
-
|
380
|
-
specify("localize currency", function(){
|
381
|
-
expect(I18n.l("currency", 1234567)).toBeEqualTo("$1,234,567.00");
|
382
|
-
});
|
383
|
-
|
384
|
-
specify("parse date", function(){
|
385
|
-
expected = new Date(2009, 0, 24, 0, 0, 0);
|
386
|
-
actual = I18n.parseDate("2009-01-24");
|
387
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
388
|
-
|
389
|
-
expected = new Date(2009, 0, 24, 0, 15, 0);
|
390
|
-
actual = I18n.parseDate("2009-01-24 00:15:00");
|
391
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
392
|
-
|
393
|
-
expected = new Date(2009, 0, 24, 0, 0, 15);
|
394
|
-
actual = I18n.parseDate("2009-01-24 00:00:15");
|
395
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
396
|
-
|
397
|
-
expected = new Date(2009, 0, 24, 15, 33, 44);
|
398
|
-
actual = I18n.parseDate("2009-01-24 15:33:44");
|
399
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
400
|
-
|
401
|
-
expected = new Date(2009, 0, 24, 0, 0, 0);
|
402
|
-
actual = I18n.parseDate(expected.getTime());
|
403
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
404
|
-
|
405
|
-
expected = new Date(2009, 0, 24, 0, 0, 0);
|
406
|
-
actual = I18n.parseDate("01/24/2009");
|
407
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
408
|
-
|
409
|
-
expected = new Date(2009, 0, 24, 14, 33, 55);
|
410
|
-
actual = I18n.parseDate(expected).toString();
|
411
|
-
expect(actual).toBeEqualTo(expected.toString());
|
412
|
-
|
413
|
-
expected = new Date(2009, 0, 24, 15, 33, 44);
|
414
|
-
actual = I18n.parseDate("2009-01-24T15:33:44");
|
415
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
416
|
-
|
417
|
-
expected = new Date(Date.UTC(2011, 6, 20, 12, 51, 55));
|
418
|
-
actual = I18n.parseDate("2011-07-20T12:51:55+0000");
|
419
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
420
|
-
|
421
|
-
expected = new Date(Date.UTC(2011, 6, 20, 13, 03, 39));
|
422
|
-
actual = I18n.parseDate("Wed Jul 20 13:03:39 +0000 2011");
|
423
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
424
|
-
|
425
|
-
expected = new Date(Date.UTC(2009, 0, 24, 15, 33, 44));
|
426
|
-
actual = I18n.parseDate("2009-01-24T15:33:44Z");
|
427
|
-
expect(actual.toString()).toBeEqualTo(expected.toString());
|
428
|
-
});
|
429
|
-
|
430
|
-
specify("date formatting", function(){
|
431
|
-
I18n.locale = "pt-BR";
|
432
|
-
|
433
|
-
// 2009-04-26 19:35:44 (Sunday)
|
434
|
-
var date = new Date(2009, 3, 26, 19, 35, 44);
|
435
|
-
|
436
|
-
// short week day
|
437
|
-
expect(I18n.strftime(date, "%a")).toBeEqualTo("Dom");
|
438
|
-
|
439
|
-
// full week day
|
440
|
-
expect(I18n.strftime(date, "%A")).toBeEqualTo("Domingo");
|
441
|
-
|
442
|
-
// short month
|
443
|
-
expect(I18n.strftime(date, "%b")).toBeEqualTo("Abr");
|
444
|
-
|
445
|
-
// full month
|
446
|
-
expect(I18n.strftime(date, "%B")).toBeEqualTo("Abril");
|
447
|
-
|
448
|
-
// day
|
449
|
-
expect(I18n.strftime(date, "%d")).toBeEqualTo("26");
|
450
|
-
|
451
|
-
// 24-hour
|
452
|
-
expect(I18n.strftime(date, "%H")).toBeEqualTo("19");
|
453
|
-
|
454
|
-
// 12-hour
|
455
|
-
expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
|
456
|
-
|
457
|
-
// month
|
458
|
-
expect(I18n.strftime(date, "%m")).toBeEqualTo("04");
|
459
|
-
|
460
|
-
// minutes
|
461
|
-
expect(I18n.strftime(date, "%M")).toBeEqualTo("35");
|
462
|
-
|
463
|
-
// meridian
|
464
|
-
expect(I18n.strftime(date, "%p")).toBeEqualTo("PM");
|
465
|
-
|
466
|
-
// seconds
|
467
|
-
expect(I18n.strftime(date, "%S")).toBeEqualTo("44");
|
468
|
-
|
469
|
-
// week day
|
470
|
-
expect(I18n.strftime(date, "%w")).toBeEqualTo("0");
|
471
|
-
|
472
|
-
// short year
|
473
|
-
expect(I18n.strftime(date, "%y")).toBeEqualTo("09");
|
474
|
-
|
475
|
-
// full year
|
476
|
-
expect(I18n.strftime(date, "%Y")).toBeEqualTo("2009");
|
477
|
-
});
|
478
|
-
|
479
|
-
specify("date formatting without padding", function(){
|
480
|
-
I18n.locale = "pt-BR";
|
481
|
-
|
482
|
-
// 2009-04-26 19:35:44 (Sunday)
|
483
|
-
var date = new Date(2009, 3, 9, 7, 8, 9);
|
484
|
-
|
485
|
-
// 24-hour without padding
|
486
|
-
expect(I18n.strftime(date, "%-H")).toBeEqualTo("7");
|
487
|
-
|
488
|
-
// 12-hour without padding
|
489
|
-
expect(I18n.strftime(date, "%-I")).toBeEqualTo("7");
|
490
|
-
|
491
|
-
// minutes without padding
|
492
|
-
expect(I18n.strftime(date, "%-M")).toBeEqualTo("8");
|
493
|
-
|
494
|
-
// seconds without padding
|
495
|
-
expect(I18n.strftime(date, "%-S")).toBeEqualTo("9");
|
496
|
-
|
497
|
-
// short year without padding
|
498
|
-
expect(I18n.strftime(date, "%-y")).toBeEqualTo("9");
|
499
|
-
|
500
|
-
// month without padding
|
501
|
-
expect(I18n.strftime(date, "%-m")).toBeEqualTo("4");
|
502
|
-
|
503
|
-
// day without padding
|
504
|
-
expect(I18n.strftime(date, "%-d")).toBeEqualTo("9");
|
505
|
-
expect(I18n.strftime(date, "%e")).toBeEqualTo("9");
|
506
|
-
});
|
507
|
-
|
508
|
-
specify("date formatting with padding", function(){
|
509
|
-
I18n.locale = "pt-BR";
|
510
|
-
|
511
|
-
// 2009-04-26 19:35:44 (Sunday)
|
512
|
-
var date = new Date(2009, 3, 9, 7, 8, 9);
|
513
|
-
|
514
|
-
// 24-hour
|
515
|
-
expect(I18n.strftime(date, "%H")).toBeEqualTo("07");
|
516
|
-
|
517
|
-
// 12-hour
|
518
|
-
expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
|
519
|
-
|
520
|
-
// minutes
|
521
|
-
expect(I18n.strftime(date, "%M")).toBeEqualTo("08");
|
522
|
-
|
523
|
-
// seconds
|
524
|
-
expect(I18n.strftime(date, "%S")).toBeEqualTo("09");
|
525
|
-
|
526
|
-
// short year
|
527
|
-
expect(I18n.strftime(date, "%y")).toBeEqualTo("09");
|
528
|
-
|
529
|
-
// month
|
530
|
-
expect(I18n.strftime(date, "%m")).toBeEqualTo("04");
|
531
|
-
|
532
|
-
// day
|
533
|
-
expect(I18n.strftime(date, "%d")).toBeEqualTo("09");
|
534
|
-
});
|
535
|
-
|
536
|
-
specify("date formatting with negative time zone", function(){
|
537
|
-
I18n.locale = "pt-BR";
|
538
|
-
var date = new Date(2009, 3, 26, 19, 35, 44);
|
539
|
-
stub(date, "getTimezoneOffset()", 345);
|
540
|
-
|
541
|
-
expect(I18n.strftime(date, "%z")).toMatch(/^(\+|-)[\d]{4}$/);
|
542
|
-
expect(I18n.strftime(date, "%z")).toBeEqualTo("-0545");
|
543
|
-
});
|
544
|
-
|
545
|
-
specify("date formatting with positive time zone", function(){
|
546
|
-
I18n.locale = "pt-BR";
|
547
|
-
var date = new Date(2009, 3, 26, 19, 35, 44);
|
548
|
-
stub(date, "getTimezoneOffset()", -345);
|
549
|
-
|
550
|
-
expect(I18n.strftime(date, "%z")).toMatch(/^(\+|-)[\d]{4}$/);
|
551
|
-
expect(I18n.strftime(date, "%z")).toBeEqualTo("+0545");
|
552
|
-
});
|
553
|
-
|
554
|
-
specify("date formatting with custom meridian", function(){
|
555
|
-
I18n.locale = "en-US";
|
556
|
-
var date = new Date(2009, 3, 26, 19, 35, 44);
|
557
|
-
expect(I18n.strftime(date, "%p")).toBeEqualTo("pm");
|
558
|
-
});
|
559
|
-
|
560
|
-
specify("date formatting meridian boundaries", function(){
|
561
|
-
I18n.locale = "en-US";
|
562
|
-
var date = new Date(2009, 3, 26, 0, 35, 44);
|
563
|
-
expect(I18n.strftime(date, "%p")).toBeEqualTo("am");
|
564
|
-
|
565
|
-
date = new Date(2009, 3, 26, 12, 35, 44);
|
566
|
-
expect(I18n.strftime(date, "%p")).toBeEqualTo("pm");
|
567
|
-
});
|
568
|
-
|
569
|
-
specify("date formatting hour12 values", function(){
|
570
|
-
I18n.locale = "pt-BR";
|
571
|
-
var date = new Date(2009, 3, 26, 19, 35, 44);
|
572
|
-
expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
|
573
|
-
|
574
|
-
date = new Date(2009, 3, 26, 12, 35, 44);
|
575
|
-
expect(I18n.strftime(date, "%I")).toBeEqualTo("12");
|
576
|
-
|
577
|
-
date = new Date(2009, 3, 26, 0, 35, 44);
|
578
|
-
expect(I18n.strftime(date, "%I")).toBeEqualTo("12");
|
579
|
-
});
|
580
|
-
|
581
|
-
specify("localize date strings", function(){
|
582
|
-
I18n.locale = "pt-BR";
|
583
|
-
|
584
|
-
expect(I18n.l("date.formats.default", "2009-11-29")).toBeEqualTo("29/11/2009");
|
585
|
-
expect(I18n.l("date.formats.short", "2009-01-07")).toBeEqualTo("07 de Janeiro");
|
586
|
-
expect(I18n.l("date.formats.long", "2009-01-07")).toBeEqualTo("07 de Janeiro de 2009");
|
587
|
-
});
|
588
|
-
|
589
|
-
specify("localize time strings", function(){
|
590
|
-
I18n.locale = "pt-BR";
|
591
|
-
|
592
|
-
expect(I18n.l("time.formats.default", "2009-11-29 15:07:59")).toBeEqualTo("Domingo, 29 de Novembro de 2009, 15:07 h");
|
593
|
-
expect(I18n.l("time.formats.short", "2009-01-07 09:12:35")).toBeEqualTo("07/01, 09:12 h");
|
594
|
-
expect(I18n.l("time.formats.long", "2009-11-29 15:07:59")).toBeEqualTo("Domingo, 29 de Novembro de 2009, 15:07 h");
|
595
|
-
});
|
596
|
-
|
597
|
-
specify("localize percentage", function(){
|
598
|
-
I18n.locale = "pt-BR";
|
599
|
-
expect(I18n.l("percentage", 123.45)).toBeEqualTo("123,45%");
|
600
|
-
});
|
601
|
-
|
602
|
-
specify("default value for simple translation", function(){
|
603
|
-
actual = I18n.t("warning", {defaultValue: "Warning!"});
|
604
|
-
expect(actual).toBeEqualTo("Warning!");
|
605
|
-
});
|
606
|
-
|
607
|
-
specify("default value with interpolation", function(){
|
608
|
-
actual = I18n.t(
|
609
|
-
"alert",
|
610
|
-
{defaultValue: "Attention! {{message}}", message: "You're out of quota!"}
|
611
|
-
);
|
612
|
-
|
613
|
-
expect(actual).toBeEqualTo("Attention! You're out of quota!");
|
614
|
-
});
|
615
|
-
|
616
|
-
specify("default value should not be used when scope exist", function(){
|
617
|
-
actual = I18n.t("hello", {defaultValue: "What's up?"});
|
618
|
-
expect(actual).toBeEqualTo("Hello World!");
|
619
|
-
});
|
620
|
-
|
621
|
-
specify("default value for pluralize", function(){
|
622
|
-
options = {defaultValue: {
|
623
|
-
none: "No things here!",
|
624
|
-
one: "There is {{count}} thing here!",
|
625
|
-
other: "There are {{count}} things here!"
|
626
|
-
}};
|
627
|
-
|
628
|
-
expect(I18n.p(0, "things", options)).toBeEqualTo("No things here!");
|
629
|
-
expect(I18n.p(1, "things", options)).toBeEqualTo("There is 1 thing here!");
|
630
|
-
expect(I18n.p(5, "things", options)).toBeEqualTo("There are 5 things here!");
|
631
|
-
});
|
632
|
-
|
633
|
-
specify("default value for pluralize should not be used when scope exist", function(){
|
634
|
-
options = {defaultValue: {
|
635
|
-
none: "No things here!",
|
636
|
-
one: "There is {{count}} thing here!",
|
637
|
-
other: "There are {{count}} things here!"
|
638
|
-
}};
|
639
|
-
|
640
|
-
expect(I18n.pluralize(0, "inbox", options)).toBeEqualTo("You have no messages");
|
641
|
-
expect(I18n.pluralize(1, "inbox", options)).toBeEqualTo("You have 1 message");
|
642
|
-
expect(I18n.pluralize(5, "inbox", options)).toBeEqualTo("You have 5 messages");
|
643
|
-
});
|
644
|
-
|
645
|
-
specify("prepare options", function(){
|
646
|
-
options = I18n.prepareOptions(
|
647
|
-
{name: "Mary Doe"},
|
648
|
-
{name: "John Doe", role: "user"}
|
649
|
-
);
|
650
|
-
|
651
|
-
expect(options["name"]).toBeEqualTo("Mary Doe");
|
652
|
-
expect(options["role"]).toBeEqualTo("user");
|
653
|
-
});
|
654
|
-
|
655
|
-
specify("prepare options with multiple options", function(){
|
656
|
-
options = I18n.prepareOptions(
|
657
|
-
{name: "Mary Doe"},
|
658
|
-
{name: "John Doe", role: "user"},
|
659
|
-
{age: 33},
|
660
|
-
{email: "mary@doe.com", url: "http://marydoe.com"},
|
661
|
-
{role: "admin", email: "john@doe.com"}
|
662
|
-
);
|
663
|
-
|
664
|
-
expect(options["name"]).toBeEqualTo("Mary Doe");
|
665
|
-
expect(options["role"]).toBeEqualTo("user");
|
666
|
-
expect(options["age"]).toBeEqualTo(33);
|
667
|
-
expect(options["email"]).toBeEqualTo("mary@doe.com");
|
668
|
-
expect(options["url"]).toBeEqualTo("http://marydoe.com");
|
669
|
-
});
|
670
|
-
|
671
|
-
specify("prepare options should return an empty hash when values are null", function(){
|
672
|
-
expect({}).toBeEqualTo(I18n.prepareOptions(null, null));
|
673
|
-
});
|
674
|
-
|
675
|
-
specify("percentage with defaults", function(){
|
676
|
-
expect(I18n.toPercentage(1234)).toBeEqualTo("1234.000%");
|
677
|
-
});
|
678
|
-
|
679
|
-
specify("percentage with custom options", function(){
|
680
|
-
actual = I18n.toPercentage(1234, {delimiter: "_", precision: 0});
|
681
|
-
expect(actual).toBeEqualTo("1_234%");
|
682
|
-
});
|
683
|
-
|
684
|
-
specify("percentage with translation", function(){
|
685
|
-
I18n.translations.en.number = {
|
686
|
-
percentage: {
|
687
|
-
format: {
|
688
|
-
precision: 2,
|
689
|
-
delimiter: ".",
|
690
|
-
separator: ","
|
691
|
-
}
|
692
|
-
}
|
693
|
-
};
|
694
|
-
|
695
|
-
expect(I18n.toPercentage(1234)).toBeEqualTo("1.234,00%");
|
696
|
-
});
|
697
|
-
|
698
|
-
specify("percentage with translation and custom options", function(){
|
699
|
-
I18n.translations.en.number = {
|
700
|
-
percentage: {
|
701
|
-
format: {
|
702
|
-
precision: 2,
|
703
|
-
delimiter: ".",
|
704
|
-
separator: ","
|
705
|
-
}
|
706
|
-
}
|
707
|
-
};
|
708
|
-
|
709
|
-
actual = I18n.toPercentage(1234, {precision: 4, delimiter: "-", separator: "+"});
|
710
|
-
expect(actual).toBeEqualTo("1-234+0000%");
|
711
|
-
});
|
712
|
-
|
713
|
-
specify("scope option as string", function(){
|
714
|
-
actual = I18n.t("stranger", {scope: "greetings"});
|
715
|
-
expect(actual).toBeEqualTo("Hello stranger!");
|
716
|
-
});
|
717
|
-
|
718
|
-
specify("scope as array", function(){
|
719
|
-
actual = I18n.t(["greetings", "stranger"]);
|
720
|
-
expect(actual).toBeEqualTo("Hello stranger!");
|
721
|
-
});
|
722
|
-
|
723
|
-
specify("new placeholder syntax", function(){
|
724
|
-
I18n.translations["en"]["new_syntax"] = "Hi %{name}!";
|
725
|
-
actual = I18n.t("new_syntax", {name: "John"});
|
726
|
-
expect(actual).toBeEqualTo("Hi John!");
|
727
|
-
});
|
728
|
-
|
729
|
-
specify("return translation for custom scope separator", function(){
|
730
|
-
I18n.defaultSeparator = "•";
|
731
|
-
actual = I18n.t("greetings•stranger");
|
732
|
-
expect(actual).toBeEqualTo("Hello stranger!");
|
733
|
-
});
|
734
|
-
|
735
|
-
specify("return number as human size", function(){
|
736
|
-
kb = 1024;
|
737
|
-
|
738
|
-
expect(I18n.toHumanSize(1)).toBeEqualTo("1Byte");
|
739
|
-
expect(I18n.toHumanSize(100)).toBeEqualTo("100Bytes");
|
740
|
-
|
741
|
-
expect(I18n.toHumanSize(kb)).toBeEqualTo("1KB");
|
742
|
-
expect(I18n.toHumanSize(kb * 1.5)).toBeEqualTo("1.5KB");
|
743
|
-
|
744
|
-
expect(I18n.toHumanSize(kb * kb)).toBeEqualTo("1MB");
|
745
|
-
expect(I18n.toHumanSize(kb * kb * 1.5)).toBeEqualTo("1.5MB");
|
746
|
-
|
747
|
-
expect(I18n.toHumanSize(kb * kb * kb)).toBeEqualTo("1GB");
|
748
|
-
expect(I18n.toHumanSize(kb * kb * kb * 1.5)).toBeEqualTo("1.5GB");
|
749
|
-
|
750
|
-
expect(I18n.toHumanSize(kb * kb * kb * kb)).toBeEqualTo("1TB");
|
751
|
-
expect(I18n.toHumanSize(kb * kb * kb * kb * 1.5)).toBeEqualTo("1.5TB");
|
752
|
-
|
753
|
-
expect(I18n.toHumanSize(kb * kb * kb * kb * kb)).toBeEqualTo("1024TB");
|
754
|
-
});
|
755
|
-
|
756
|
-
specify("return number as human size using custom options", function(){
|
757
|
-
expect(I18n.toHumanSize(1024 * 1.6, {precision: 0})).toBeEqualTo("2KB");
|
758
|
-
});
|
759
|
-
|
760
|
-
specify("return number without insignificant zeros", function(){
|
761
|
-
options = {precision: 4, strip_insignificant_zeros: true};
|
762
|
-
|
763
|
-
expect(I18n.toNumber(65, options)).toBeEqualTo("65");
|
764
|
-
expect(I18n.toNumber(1.2, options)).toBeEqualTo("1.2");
|
765
|
-
expect(I18n.toCurrency(1.2, options)).toBeEqualTo("$1.2");
|
766
|
-
expect(I18n.toHumanSize(1.2, options)).toBeEqualTo("1.2Bytes");
|
767
|
-
});
|
768
|
-
});
|