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 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.default_locale` when not found using requested locale)
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.1
3
+ // Version: 0.5.2
4
4
  //
5
5
  (function() {
6
6
 
7
7
  I18n = {};
8
8
 
9
- // Check if an Array contains an object
9
+ // Check if Array contains an object
10
10
  function isInArray(a, obj) {
11
-    var i = a.length;
12
-    while (i--) {
13
-       if (a[i] === obj) {
14
-           return true;
15
-       }
16
-    }
17
-    return false;
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.current_locale = function() {
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.current_locale(), key, opts.defaultValue);
89
+ var value = this.lookup(I18n.currentLocale(), key, opts.defaultValue);
90
90
 
91
- // fall back to I18n.default_locale for missing translations
92
- if (value == null && I18n.locale != I18n.default_locale) value = this.lookup(I18n.default_locale, key, opts.defaultLocale);
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.current_locale(), ["number", "format"]);
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.current_locale(), I18n.keyToArray(scope));
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.current_locale(), ["date"]);
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.current_locale(), ["time"]);
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.current_locale(), ["number", "format"]),
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.current_locale(), ["number", "currency", "format"]),
309
- this.lookup(I18n.current_locale(), ["number", "format"]),
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.current_locale(), ["number", "percentage", "format"]),
359
- this.lookup(I18n.current_locale(), ["number", "format"]),
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.current_locale()](value, count);
370
+ return I18n.plurals[I18n.currentLocale()](value, count);
371
371
  };
372
372
 
373
373
  // Default pluralization rules
374
- I18n.default_pluralization_rule = function(value, count) {
374
+ I18n.defaultPluralizationRule = function(value, count) {
375
375
  return count == 1 ? value.one : value.other;
376
376
  }
377
- I18n.other_default_pluralization_rule = function(value, count) {
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.default_pluralization_rule,
384
- "am": I18n.other_default_pluralization_rule,
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.default_pluralization_rule,
394
- "bh": I18n.default_pluralization_rule,
395
- "bn": I18n.default_pluralization_rule,
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.default_pluralization_rule,
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.default_pluralization_rule,
404
- "de": I18n.default_pluralization_rule,
403
+ "da": I18n.defaultPluralizationRule,
404
+ "de": I18n.defaultPluralizationRule,
405
405
  "dz": function(value, count) { return value.other; },
406
- "el": I18n.default_pluralization_rule,
407
- "en": I18n.default_pluralization_rule,
408
- "eo": I18n.default_pluralization_rule,
409
- "es": I18n.default_pluralization_rule,
410
- "et": I18n.default_pluralization_rule,
411
- "eu": I18n.default_pluralization_rule,
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.default_pluralization_rule,
414
- "fil": I18n.other_default_pluralization_rule,
415
- "fo": I18n.default_pluralization_rule,
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.default_pluralization_rule,
418
- "fy": I18n.default_pluralization_rule,
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.default_pluralization_rule,
421
- "gu": I18n.default_pluralization_rule,
422
- "guw": I18n.other_default_pluralization_rule,
423
- "ha": I18n.default_pluralization_rule,
424
- "he": I18n.default_pluralization_rule,
425
- "hi": I18n.other_default_pluralization_rule,
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.default_pluralization_rule,
432
- "it": I18n.default_pluralization_rule,
433
- "iw": I18n.default_pluralization_rule,
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.default_pluralization_rule,
441
- "lb": I18n.default_pluralization_rule,
442
- "ln": I18n.other_default_pluralization_rule,
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.default_pluralization_rule,
447
+ "mg": I18n.defaultPluralizationRule,
448
448
  "mk": function(value, count) { return count % 10 == 1 ? value.one : value.other; },
449
- "ml": I18n.default_pluralization_rule,
450
- "mn": I18n.default_pluralization_rule,
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.default_pluralization_rule,
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.default_pluralization_rule,
459
- "nb": I18n.default_pluralization_rule,
460
- "ne": I18n.default_pluralization_rule,
461
- "nl": I18n.default_pluralization_rule,
462
- "nn": I18n.default_pluralization_rule,
463
- "no": I18n.default_pluralization_rule,
464
- "nso": I18n.other_default_pluralization_rule,
465
- "or": I18n.default_pluralization_rule,
466
- "pa": I18n.default_pluralization_rule,
467
- "pap": I18n.default_pluralization_rule,
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.default_pluralization_rule,
472
- "pt": I18n.other_default_pluralization_rule,
473
- "pt-PT": I18n.default_pluralization_rule,
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.default_pluralization_rule,
490
- "sq": I18n.default_pluralization_rule,
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.default_pluralization_rule,
495
- "sw": I18n.default_pluralization_rule,
496
- "ta": I18n.default_pluralization_rule,
497
- "te": I18n.default_pluralization_rule,
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.other_default_pluralization_rule,
500
- "tk": I18n.default_pluralization_rule,
501
- "tl": I18n.other_default_pluralization_rule,
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.default_pluralization_rule,
507
+ "ur": I18n.defaultPluralizationRule,
508
508
  "vi": function(value, count) { return value.other; },
509
- "wa": I18n.other_default_pluralization_rule,
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.default_pluralization_rule
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.current_locale();
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.default_locale = I18n.locale || '<%= I18n.default_locale %>';
3
+ I18n.defaultLocale = '<%= I18n.default_locale %>';
4
4
  I18n.translations = I18n.translations || <%= ActiveSupport::JSON.encode(@translations).html_safe %>;
@@ -1,3 +1,3 @@
1
1
  module ExvoGlobalize
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -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.default_locale when there is no translation available for the requested locale", function() {
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("title", {scope: "page"})).toEqual("Title")
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
  })
@@ -1,5 +1,5 @@
1
1
  I18n.locale = 'en'
2
- I18n.default_locale = 'en'
2
+ I18n.defaultLocale = 'en'
3
3
 
4
4
  I18n.translations = {
5
5
  en: {
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: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
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-19 00:00:00 +02:00
18
+ date: 2011-09-20 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency