exvo_globalize 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -2
- data/app/assets/javascripts/exvo_globalize_i18n.js +86 -86
- data/app/views/globalize_translations/show.js.erb +1 -1
- data/lib/exvo_globalize/version.rb +1 -1
- data/spec/javascripts/exvo_globalize_i18n_spec.js +3 -2
- data/spec/javascripts/fixtures/translations.js +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -14,10 +14,11 @@ Ruby/Rails features:
|
|
14
14
|
Javascript features:
|
15
15
|
|
16
16
|
* all translations defined in `config/locales/*` are available in javascript
|
17
|
-
* localization support for dates, times, numbers, currencies (localization rules are read from `config/locales/*.(yml|rb)`)
|
18
|
-
* locale fallback support (will search for translation using `I18n.
|
17
|
+
* localization support for dates, times, numbers, currencies (localization rules are read from `config/locales/*.(yml|rb)`) (support at the same level as in Ruby/Rails)
|
18
|
+
* locale fallback support (will search for translation using `I18n.defaultLocale` when not found using requested locale)
|
19
19
|
* global t() and l() helpers to translate and localize phrases, respectively
|
20
20
|
* does not depend on any other external javascript library
|
21
|
+
* pluralizations rules defined for 108 languages (in `exvo_globalize_i18n.js`)
|
21
22
|
|
22
23
|
|
23
24
|
This gem also integrates your application with [Globalize](http://store.exvo.com/apps/shops/globalize/items/globalize-125). Globalize is a service for website owners, who want to translate their websites into multiple languages by using human (as opposed to machine/automatic) translators.
|
@@ -1,20 +1,20 @@
|
|
1
1
|
//
|
2
2
|
// exvo_globalize_i18n.js
|
3
|
-
// Version: 0.5.
|
3
|
+
// Version: 0.5.2
|
4
4
|
//
|
5
5
|
(function() {
|
6
6
|
|
7
7
|
I18n = {};
|
8
8
|
|
9
|
-
// Check if
|
9
|
+
// Check if Array contains an object
|
10
10
|
function isInArray(a, obj) {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
var i = a.length;
|
12
|
+
while (i--) {
|
13
|
+
if (a[i] === obj) {
|
14
|
+
return true;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
return false;
|
18
18
|
};
|
19
19
|
|
20
20
|
var interpolatePattern = /%\{([^}]+)\}/g;
|
@@ -33,7 +33,7 @@
|
|
33
33
|
return key.split('.');
|
34
34
|
};
|
35
35
|
|
36
|
-
I18n.
|
36
|
+
I18n.currentLocale = function() {
|
37
37
|
return I18n.locale || I18n.defaultLocale;
|
38
38
|
};
|
39
39
|
|
@@ -86,10 +86,10 @@
|
|
86
86
|
opts = opts || {};
|
87
87
|
opts.defaultValue = opts.defaultValue || null;
|
88
88
|
key = I18n.keyToArray(opts.scope).concat(I18n.keyToArray(key));
|
89
|
-
var value = this.lookup(I18n.
|
89
|
+
var value = this.lookup(I18n.currentLocale(), key, opts.defaultValue);
|
90
90
|
|
91
|
-
// fall back to I18n.
|
92
|
-
if (value == null && I18n.locale != I18n.
|
91
|
+
// fall back to I18n.defaultLocale for missing translations
|
92
|
+
if (value == null && I18n.locale != I18n.defaultLocale) value = this.lookup(I18n.defaultLocale, key, opts.defaultLocale);
|
93
93
|
|
94
94
|
if (typeof value != "string" && value) value = this.pluralize(value, opts.count);
|
95
95
|
if (typeof value == "string") value = I18n.interpolate(value, opts);
|
@@ -131,7 +131,7 @@
|
|
131
131
|
case "currency":
|
132
132
|
return this.toCurrency(value);
|
133
133
|
case "number":
|
134
|
-
scope = this.lookup(I18n.
|
134
|
+
scope = this.lookup(I18n.currentLocale(), ["number", "format"]);
|
135
135
|
return this.toNumber(value, scope);
|
136
136
|
case "percentage":
|
137
137
|
return this.toPercentage(value);
|
@@ -179,7 +179,7 @@
|
|
179
179
|
|
180
180
|
I18n.toTime = function(scope, d) {
|
181
181
|
var date = this.parseDate(d);
|
182
|
-
var format = this.lookup(I18n.
|
182
|
+
var format = this.lookup(I18n.currentLocale(), I18n.keyToArray(scope));
|
183
183
|
|
184
184
|
if (date.toString().match(/invalid/i)) {
|
185
185
|
return date.toString();
|
@@ -193,14 +193,14 @@
|
|
193
193
|
};
|
194
194
|
|
195
195
|
I18n.strftime = function(date, format) {
|
196
|
-
var options = this.lookup(I18n.
|
196
|
+
var options = this.lookup(I18n.currentLocale(), ["date"]);
|
197
197
|
|
198
198
|
if (!options) {
|
199
199
|
return date.toString();
|
200
200
|
}
|
201
201
|
|
202
202
|
// get meridian from ":time" i18n key
|
203
|
-
options.time = this.lookup(I18n.
|
203
|
+
options.time = this.lookup(I18n.currentLocale(), ["time"]);
|
204
204
|
if (!options.time || !options.time.am || !options.time.pm) {
|
205
205
|
options.time = { am: "AM", pm: "PM" };
|
206
206
|
}
|
@@ -260,7 +260,7 @@
|
|
260
260
|
I18n.toNumber = function(number, options) {
|
261
261
|
options = this.prepareOptions(
|
262
262
|
options,
|
263
|
-
this.lookup(I18n.
|
263
|
+
this.lookup(I18n.currentLocale(), ["number", "format"]),
|
264
264
|
{precision: 3, separator: ".", delimiter: ",", strip_insignificant_zeros: false}
|
265
265
|
);
|
266
266
|
|
@@ -305,8 +305,8 @@
|
|
305
305
|
I18n.toCurrency = function(number, options) {
|
306
306
|
options = this.prepareOptions(
|
307
307
|
options,
|
308
|
-
this.lookup(I18n.
|
309
|
-
this.lookup(I18n.
|
308
|
+
this.lookup(I18n.currentLocale(), ["number", "currency", "format"]),
|
309
|
+
this.lookup(I18n.currentLocale(), ["number", "format"]),
|
310
310
|
{unit: "$", precision: 2, format: "%u%n", delimiter: ",", separator: "."}
|
311
311
|
);
|
312
312
|
|
@@ -355,8 +355,8 @@
|
|
355
355
|
I18n.toPercentage = function(number, options) {
|
356
356
|
options = this.prepareOptions(
|
357
357
|
options,
|
358
|
-
this.lookup(I18n.
|
359
|
-
this.lookup(I18n.
|
358
|
+
this.lookup(I18n.currentLocale(), ["number", "percentage", "format"]),
|
359
|
+
this.lookup(I18n.currentLocale(), ["number", "format"]),
|
360
360
|
{precision: 3, separator: ".", delimiter: ""}
|
361
361
|
);
|
362
362
|
|
@@ -367,21 +367,21 @@
|
|
367
367
|
// Pluralization function
|
368
368
|
I18n.pluralize = function(value, count) {
|
369
369
|
if (typeof count != 'number') return value;
|
370
|
-
return I18n.plurals[I18n.
|
370
|
+
return I18n.plurals[I18n.currentLocale()](value, count);
|
371
371
|
};
|
372
372
|
|
373
373
|
// Default pluralization rules
|
374
|
-
I18n.
|
374
|
+
I18n.defaultPluralizationRule = function(value, count) {
|
375
375
|
return count == 1 ? value.one : value.other;
|
376
376
|
}
|
377
|
-
I18n.
|
377
|
+
I18n.otherDefaultPluralizationRule = function(value, count) {
|
378
378
|
return count == 1 || count == 0 ? value.one : value.other;
|
379
379
|
}
|
380
380
|
|
381
381
|
// Pluralization Rules for each language
|
382
382
|
I18n.plurals = {
|
383
|
-
"af": I18n.
|
384
|
-
"am": I18n.
|
383
|
+
"af": I18n.defaultPluralizationRule,
|
384
|
+
"am": I18n.otherDefaultPluralizationRule,
|
385
385
|
"ar": function(value, count) {
|
386
386
|
if (typeof count != 'number') return value;
|
387
387
|
return count == 0 ? value.zero : count == 1 ? value.one : count == 2 ? value.two : isInArray([3, 4, 5, 6, 7, 8, 9, 10], count % 100) ? value.few : isInArray([3, 4, 5, 6, 7, 8, 9, 10], count % 100) ? value.few : isInArray([11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], count % 100) ? value.many : value.other;
|
@@ -390,87 +390,87 @@
|
|
390
390
|
"be": function(value, count) {
|
391
391
|
return count % 10 == 1 && count % 100 != 11 ? value.one : isInArray([2,3,4], count % 10) && !isInArray([12,13,14], count % 100) ? value.few : count % 10 == 0 || isInArray([5,6,7,8,9], count % 10) || isInArray([11,12,13,14], count % 100) ? value.many : valye.other;
|
392
392
|
},
|
393
|
-
"bg": I18n.
|
394
|
-
"bh": I18n.
|
395
|
-
"bn": I18n.
|
393
|
+
"bg": I18n.defaultPluralizationRule,
|
394
|
+
"bh": I18n.defaultPluralizationRule,
|
395
|
+
"bn": I18n.defaultPluralizationRule,
|
396
396
|
"bo": function(value, count) { return value.other; },
|
397
397
|
"bs": function(value, count) {
|
398
398
|
return count % 10 == 1 && count % 100 != 11 ? value.one : isInArray([2,3,4], count % 10) && !isInArray([12,13,14], count % 100) ? value.few : count % 10 == 0 || isInArray([5,6,7,8,9], count % 10) || isInArray([11,12,13,14], count % 100) ? value.many : value.other;
|
399
399
|
},
|
400
|
-
"ca": I18n.
|
400
|
+
"ca": I18n.defaultPluralizationRule,
|
401
401
|
"cs": function(value, count) { return count == 1 ? value.one : isInArray([2,3,4], count) ? value.few : value.other; },
|
402
402
|
"cy": function(value, count) { return count == 1 ? value.one : count == 2 ? value.two : count == 8 || count == 11 ? value.many : value.other; },
|
403
|
-
"da": I18n.
|
404
|
-
"de": I18n.
|
403
|
+
"da": I18n.defaultPluralizationRule,
|
404
|
+
"de": I18n.defaultPluralizationRule,
|
405
405
|
"dz": function(value, count) { return value.other; },
|
406
|
-
"el": I18n.
|
407
|
-
"en": I18n.
|
408
|
-
"eo": I18n.
|
409
|
-
"es": I18n.
|
410
|
-
"et": I18n.
|
411
|
-
"eu": I18n.
|
406
|
+
"el": I18n.defaultPluralizationRule,
|
407
|
+
"en": I18n.defaultPluralizationRule,
|
408
|
+
"eo": I18n.defaultPluralizationRule,
|
409
|
+
"es": I18n.defaultPluralizationRule,
|
410
|
+
"et": I18n.defaultPluralizationRule,
|
411
|
+
"eu": I18n.defaultPluralizationRule,
|
412
412
|
"fa": function(value, count) { return value.other; },
|
413
|
-
"fi": I18n.
|
414
|
-
"fil": I18n.
|
415
|
-
"fo": I18n.
|
413
|
+
"fi": I18n.defaultPluralizationRule,
|
414
|
+
"fil": I18n.otherDefaultPluralizationRule,
|
415
|
+
"fo": I18n.defaultPluralizationRule,
|
416
416
|
"fr": function(value, count) { return isInArray([0,1], count) ? value.one : value.other; },
|
417
|
-
"fur": I18n.
|
418
|
-
"fy": I18n.
|
417
|
+
"fur": I18n.defaultPluralizationRule,
|
418
|
+
"fy": I18n.defaultPluralizationRule,
|
419
419
|
"ga": function(value, count) { return count == 1 ? value.one : count == 2 ? value.two : value.other; },
|
420
|
-
"gl": I18n.
|
421
|
-
"gu": I18n.
|
422
|
-
"guw": I18n.
|
423
|
-
"ha": I18n.
|
424
|
-
"he": I18n.
|
425
|
-
"hi": I18n.
|
420
|
+
"gl": I18n.defaultPluralizationRule,
|
421
|
+
"gu": I18n.defaultPluralizationRule,
|
422
|
+
"guw": I18n.otherDefaultPluralizationRule,
|
423
|
+
"ha": I18n.defaultPluralizationRule,
|
424
|
+
"he": I18n.defaultPluralizationRule,
|
425
|
+
"hi": I18n.otherDefaultPluralizationRule,
|
426
426
|
"hr": function(value, count) {
|
427
427
|
return count % 10 == 1 && count % 100 != 11 ? value.one : isInArray([2,3,4], count % 10) && !isInArray([12,13,14], count % 100) ? value.few : count % 10 == 0 || isInArray([5,6,7,8,9], count % 10) || isInArray([11,12,13,14], count % 100) ? value.many : value.other;
|
428
428
|
},
|
429
429
|
"hu": function(value, count) { return value.other; },
|
430
430
|
"id": function(value, count) { return value.other; },
|
431
|
-
"is": I18n.
|
432
|
-
"it": I18n.
|
433
|
-
"iw": I18n.
|
431
|
+
"is": I18n.defaultPluralizationRule,
|
432
|
+
"it": I18n.defaultPluralizationRule,
|
433
|
+
"iw": I18n.defaultPluralizationRule,
|
434
434
|
"ja": function(value, count) { return value.other; },
|
435
435
|
"jv": function(value, count) { return value.other; },
|
436
436
|
"ka": function(value, count) { return value.other; },
|
437
437
|
"km": function(value, count) { return value.other; },
|
438
438
|
"kn": function(value, count) { return value.other; },
|
439
439
|
"ko": function(value, count) { return value.other; },
|
440
|
-
"ku": I18n.
|
441
|
-
"lb": I18n.
|
442
|
-
"ln": I18n.
|
440
|
+
"ku": I18n.defaultPluralizationRule,
|
441
|
+
"lb": I18n.defaultPluralizationRule,
|
442
|
+
"ln": I18n.otherDefaultPluralizationRule,
|
443
443
|
"lt": function(value, count) {
|
444
444
|
return count % 10 == 1 && ! isInArray([11, 12, 13, 14, 15, 16, 17, 18, 19], count % 100) ? value.one : isInArray([2, 3, 4, 5, 6, 7, 8, 9], count % 10) && ! isInArray([11, 12, 13, 14, 15, 16, 17, 18, 19], count % 100) ? value.few : value.other;
|
445
445
|
},
|
446
446
|
"lv": function(value, count) { return count == 0 ? value.zero : count % 10 == 1 && count % 100 != 11 ? value.one : value.other; },
|
447
|
-
"mg": I18n.
|
447
|
+
"mg": I18n.defaultPluralizationRule,
|
448
448
|
"mk": function(value, count) { return count % 10 == 1 ? value.one : value.other; },
|
449
|
-
"ml": I18n.
|
450
|
-
"mn": I18n.
|
449
|
+
"ml": I18n.defaultPluralizationRule,
|
450
|
+
"mn": I18n.defaultPluralizationRule,
|
451
451
|
"mo": function(value, count) { return count ==1 ? value.one : count == 0 ? value.few : value.other; },
|
452
|
-
"mr": I18n.
|
452
|
+
"mr": I18n.defaultPluralizationRule,
|
453
453
|
"ms": function(value, count) { return value.other; },
|
454
454
|
"mt": function(value, count) {
|
455
455
|
return count == 1 ? value.one : count == 0 || isInArray([2,3,4,5,6,7,8,9,10], count % 100) ? value.few : isInArray([11,12,13,14,15,16,17,18,19], count % 100) ? value.many : value.other;
|
456
456
|
},
|
457
457
|
"my": function(value, count) { return value.other; },
|
458
|
-
"nah": I18n.
|
459
|
-
"nb": I18n.
|
460
|
-
"ne": I18n.
|
461
|
-
"nl": I18n.
|
462
|
-
"nn": I18n.
|
463
|
-
"no": I18n.
|
464
|
-
"nso": I18n.
|
465
|
-
"or": I18n.
|
466
|
-
"pa": I18n.
|
467
|
-
"pap": I18n.
|
458
|
+
"nah": I18n.defaultPluralizationRule,
|
459
|
+
"nb": I18n.defaultPluralizationRule,
|
460
|
+
"ne": I18n.defaultPluralizationRule,
|
461
|
+
"nl": I18n.defaultPluralizationRule,
|
462
|
+
"nn": I18n.defaultPluralizationRule,
|
463
|
+
"no": I18n.defaultPluralizationRule,
|
464
|
+
"nso": I18n.otherDefaultPluralizationRule,
|
465
|
+
"or": I18n.defaultPluralizationRule,
|
466
|
+
"pa": I18n.defaultPluralizationRule,
|
467
|
+
"pap": I18n.defaultPluralizationRule,
|
468
468
|
"pl": function(value, count) {
|
469
469
|
return count == 1 ? value.one : isInArray([2,3,4], count % 10) && !isInArray([12,13,14], count % 100) ? value.few : value.other;
|
470
470
|
},
|
471
|
-
"ps": I18n.
|
472
|
-
"pt": I18n.
|
473
|
-
"pt-PT": I18n.
|
471
|
+
"ps": I18n.defaultPluralizationRule,
|
472
|
+
"pt": I18n.otherDefaultPluralizationRule,
|
473
|
+
"pt-PT": I18n.defaultPluralizationRule,
|
474
474
|
"ro": function(value, count) { return count == 1 ? value.one : count == 0 ? value.few : value.other; },
|
475
475
|
"ru": function(value, count) {
|
476
476
|
return count % 10 == 1 && count % 100 != 11 ? value.one : isInArray([2,3,4], count % 10) && !isInArray([12,13,14], count % 100) ? value.few : count % 10 == 0 || isInArray([5,6,7,8,9], count % 10) || isInArray([11,12,13,14], count % 100) ? value.many : value.other;
|
@@ -486,35 +486,35 @@
|
|
486
486
|
"smj": function(value, count) { return count == 1 ? value.one : count == 2 ? value.two : value.other; },
|
487
487
|
"smn": function(value, count) { return count == 1 ? value.one : count == 2 ? value.two : value.other; },
|
488
488
|
"sms": function(value, count) { return count == 1 ? value.one : count == 2 ? value.two : value.other; },
|
489
|
-
"so": I18n.
|
490
|
-
"sq": I18n.
|
489
|
+
"so": I18n.defaultPluralizationRule,
|
490
|
+
"sq": I18n.defaultPluralizationRule,
|
491
491
|
"sr": function(value, count) {
|
492
492
|
return count % 10 == 1 && count % 100 != 11 ? value.one : isInArray([2,3,4], count % 10) && ! isInArray([12,13,14], count % 100) ? value.few : count % 10 == 0 || isInArray([5,6,7,8,9], count % 10) || isInArray([11,12,13,14], count % 100) ? value.many : value.other;
|
493
493
|
},
|
494
|
-
"sv": I18n.
|
495
|
-
"sw": I18n.
|
496
|
-
"ta": I18n.
|
497
|
-
"te": I18n.
|
494
|
+
"sv": I18n.defaultPluralizationRule,
|
495
|
+
"sw": I18n.defaultPluralizationRule,
|
496
|
+
"ta": I18n.defaultPluralizationRule,
|
497
|
+
"te": I18n.defaultPluralizationRule,
|
498
498
|
"th": function(value, count) { return value.other; },
|
499
|
-
"ti": I18n.
|
500
|
-
"tk": I18n.
|
501
|
-
"tl": I18n.
|
499
|
+
"ti": I18n.otherDefaultPluralizationRule,
|
500
|
+
"tk": I18n.defaultPluralizationRule,
|
501
|
+
"tl": I18n.otherDefaultPluralizationRule,
|
502
502
|
"to": function(value, count) { return value.other; },
|
503
503
|
"tr": function(value, count) { return value.other; },
|
504
504
|
"uk": function(value, count) {
|
505
505
|
return count % 10 == 1 && count % 100 != 11 ? value.one : isInArray([2,3,4], count % 10) && !isInArray([12,13,14], count % 100) ? value.few : count % 10 == 0 || isInArray([5,6,7,8,9], count % 10) || isInArray([11,12,13,14], count % 100) ? value.many : value.other;
|
506
506
|
},
|
507
|
-
"ur": I18n.
|
507
|
+
"ur": I18n.defaultPluralizationRule,
|
508
508
|
"vi": function(value, count) { return value.other; },
|
509
|
-
"wa": I18n.
|
509
|
+
"wa": I18n.otherDefaultPluralizationRule,
|
510
510
|
"yo": function(value, count) { return value.other; },
|
511
511
|
"zh": function(value, count) { return value.other; },
|
512
|
-
"zu": I18n.
|
512
|
+
"zu": I18n.defaultPluralizationRule
|
513
513
|
}
|
514
514
|
|
515
515
|
// Returns '[missing translation: "en.missing"]' when translation is not found
|
516
516
|
I18n.missingTranslation = function(key) {
|
517
|
-
var message = '[missing translation: "' + I18n.
|
517
|
+
var message = '[missing translation: "' + I18n.currentLocale();
|
518
518
|
for (var i in key) {
|
519
519
|
message += "." + key[i];
|
520
520
|
}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
var I18n = I18n || {};
|
2
2
|
I18n.locale = I18n.locale || '<%= I18n.locale %>';
|
3
|
-
I18n.
|
3
|
+
I18n.defaultLocale = '<%= I18n.default_locale %>';
|
4
4
|
I18n.translations = I18n.translations || <%= ActiveSupport::JSON.encode(@translations).html_safe %>;
|
@@ -77,9 +77,10 @@ describe("Default value fallback", function() {
|
|
77
77
|
|
78
78
|
describe("Locale fallback", function() {
|
79
79
|
|
80
|
-
it("falls back to I18n.
|
80
|
+
it("falls back to I18n.defaultLocale when there is no translation available for the requested locale", function() {
|
81
81
|
I18n.locale = "pl"
|
82
|
-
expect(I18n.t("
|
82
|
+
expect(I18n.t("world")).toEqual("Świat") // existing translation
|
83
|
+
expect(I18n.t("title", {scope: "page"})).toEqual("Title") // missing translation
|
83
84
|
})
|
84
85
|
|
85
86
|
})
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exvo_globalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Pawe\xC5\x82 Go\xC5\x9Bcicki"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-20 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|