i18n-js 1.0.1 → 1.0.2
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.
- data/Gemfile.lock +1 -1
- data/lib/i18n-js/version.rb +1 -1
- data/source/i18n.js +15 -6
- data/spec/i18n_spec.js +6 -0
- metadata +3 -5
data/Gemfile.lock
CHANGED
data/lib/i18n-js/version.rb
CHANGED
data/source/i18n.js
CHANGED
@@ -13,6 +13,12 @@ I18n.locale = null;
|
|
13
13
|
// Set the placeholder format. Accepts `{{placeholder}}` and `%{placeholder}`.
|
14
14
|
I18n.PLACEHOLDER = /(?:\{\{|%\{)(.*?)(?:\}\}?)/gm;
|
15
15
|
|
16
|
+
I18n.isValidNode = function(obj, node) {
|
17
|
+
// local undefined variable in case another library corrupts window.undefined
|
18
|
+
var undef;
|
19
|
+
return obj[node] !== null && obj[node] !== undef;
|
20
|
+
}
|
21
|
+
|
16
22
|
I18n.lookup = function(scope, options) {
|
17
23
|
var translations = this.prepareOptions(I18n.translations);
|
18
24
|
var messages = translations[I18n.currentLocale()];
|
@@ -41,7 +47,7 @@ I18n.lookup = function(scope, options) {
|
|
41
47
|
}
|
42
48
|
}
|
43
49
|
|
44
|
-
if (!messages && options
|
50
|
+
if (!messages && this.isValidNode(options, "defaultValue")) {
|
45
51
|
messages = options.defaultValue;
|
46
52
|
}
|
47
53
|
|
@@ -67,7 +73,7 @@ I18n.prepareOptions = function() {
|
|
67
73
|
}
|
68
74
|
|
69
75
|
for (var key in opts) {
|
70
|
-
if (options
|
76
|
+
if (!this.isValidNode(options, key)) {
|
71
77
|
options[key] = opts[key];
|
72
78
|
}
|
73
79
|
}
|
@@ -91,7 +97,7 @@ I18n.interpolate = function(message, options) {
|
|
91
97
|
|
92
98
|
value = options[name];
|
93
99
|
|
94
|
-
if (options
|
100
|
+
if (!this.isValidNode(options, name)) {
|
95
101
|
value = "[missing " + placeholder + " value]";
|
96
102
|
}
|
97
103
|
|
@@ -369,13 +375,16 @@ I18n.pluralize = function(count, scope, options) {
|
|
369
375
|
|
370
376
|
switch(Math.abs(count)) {
|
371
377
|
case 0:
|
372
|
-
message =
|
378
|
+
message = this.isValidNode(translation, "zero") ? translation.zero :
|
379
|
+
this.isValidNode(translation, "none") ? translation.none :
|
380
|
+
this.isValidNode(translation, "other") ? translation.other :
|
381
|
+
this.missingTranslation(scope, "zero");
|
373
382
|
break;
|
374
383
|
case 1:
|
375
|
-
message = translation.one
|
384
|
+
message = this.isValidNode(translation, "one") ? translation.one : this.missingTranslation(scope, "one");
|
376
385
|
break;
|
377
386
|
default:
|
378
|
-
message = translation.other
|
387
|
+
message = this.isValidNode(translation, "other") ? translation.other : this.missingTranslation(scope, "other");
|
379
388
|
}
|
380
389
|
|
381
390
|
return this.interpolate(message, options);
|
data/spec/i18n_spec.js
CHANGED
@@ -216,6 +216,12 @@ describe("I18n.js", function(){
|
|
216
216
|
expect(actual).toBeEqualTo("You have no new messages (5 unread)");
|
217
217
|
});
|
218
218
|
|
219
|
+
specify("pluralize should allow empty strings", function(){
|
220
|
+
I18n.translations["en"]["inbox"]["zero"] = "";
|
221
|
+
|
222
|
+
expect(I18n.p(0, "inbox")).toBeEqualTo("");
|
223
|
+
});
|
224
|
+
|
219
225
|
specify("numbers with default settings", function(){
|
220
226
|
expect(I18n.toNumber(1)).toBeEqualTo("1.000");
|
221
227
|
expect(I18n.toNumber(12)).toBeEqualTo("12.000");
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: i18n-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nando Vieira
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-04-13 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: i18n
|
@@ -111,7 +110,6 @@ files:
|
|
111
110
|
- spec/resources/no_scope.yml
|
112
111
|
- spec/resources/simple_scope.yml
|
113
112
|
- spec/spec_helper.rb
|
114
|
-
has_rdoc: true
|
115
113
|
homepage: http://rubygems.org/gems/i18n-js
|
116
114
|
licenses: []
|
117
115
|
|
@@ -135,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
133
|
requirements: []
|
136
134
|
|
137
135
|
rubyforge_project:
|
138
|
-
rubygems_version: 1.
|
136
|
+
rubygems_version: 1.7.2
|
139
137
|
signing_key:
|
140
138
|
specification_version: 3
|
141
139
|
summary: It's a small library to provide the Rails I18n translations on the Javascript.
|