exvo_globalize 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // exvo_globalize_i18n.js
3
- // Version: 0.5.2
3
+ // Version: 0.5.3
4
4
  //
5
5
  (function() {
6
6
 
@@ -86,12 +86,17 @@
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.currentLocale(), key, opts.defaultValue);
89
+
90
+ var locale = I18n.currentLocale();
91
+ var value = this.lookup(locale, key, opts.defaultValue);
90
92
 
91
93
  // fall back to I18n.defaultLocale for missing translations
92
- if (value == null && I18n.locale != I18n.defaultLocale) value = this.lookup(I18n.defaultLocale, key, opts.defaultLocale);
94
+ if (value == null && I18n.locale != I18n.defaultLocale) {
95
+ value = this.lookup(I18n.defaultLocale, key, opts.defaultLocale);
96
+ locale = I18n.defaultLocale;
97
+ }
93
98
 
94
- if (typeof value != "string" && value) value = this.pluralize(value, opts.count);
99
+ if (typeof value != "string" && value) value = this.pluralize(locale, value, opts.count);
95
100
  if (typeof value == "string") value = I18n.interpolate(value, opts);
96
101
  if (value == null) value = this.missingTranslation(key)
97
102
  return value;
@@ -365,9 +370,9 @@
365
370
  };
366
371
 
367
372
  // Pluralization function
368
- I18n.pluralize = function(value, count) {
373
+ I18n.pluralize = function(locale, value, count) {
369
374
  if (typeof count != 'number') return value;
370
- return I18n.plurals[I18n.currentLocale()](value, count);
375
+ return I18n.plurals[locale](value, count);
371
376
  };
372
377
 
373
378
  // Default pluralization rules
@@ -1,3 +1,3 @@
1
1
  module ExvoGlobalize
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -83,6 +83,13 @@ describe("Locale fallback", function() {
83
83
  expect(I18n.t("title", {scope: "page"})).toEqual("Title") // missing translation
84
84
  })
85
85
 
86
+ it("falls back to I18n.defaultLocale even for missing pluralization keys", function() {
87
+ I18n.locale = "pl"
88
+ expect(I18n.t("friend", {count: 1})).toEqual("1 Friend")
89
+ expect(I18n.t("friend", {count: 2})).toEqual("2 Friends")
90
+ expect(I18n.t("friend", {count: 5})).toEqual("5 Friends")
91
+ })
92
+
86
93
  })
87
94
 
88
95
  describe("Localization of numbers", function() {
@@ -396,6 +403,13 @@ describe("Pluralizations", function() {
396
403
  expect(I18n.t("contact", {count: 22})).toEqual("22 Contacts")
397
404
  })
398
405
 
406
+ it("correctly pluralizes another English phrase", function() {
407
+ I18n.locale = "en"
408
+ expect(I18n.t("friend", {count: 1})).toEqual("1 Friend")
409
+ expect(I18n.t("friend", {count: 2})).toEqual("2 Friends")
410
+ expect(I18n.t("friend", {count: 22})).toEqual("22 Friends")
411
+ })
412
+
399
413
  it("correctly pluralizes the French phrase", function() {
400
414
  I18n.locale = "fr"
401
415
  expect(I18n.t("contact", {count: 0})).toEqual("0 contact")
@@ -12,6 +12,11 @@ I18n.translations = {
12
12
  other: "%{count} Contacts"
13
13
  },
14
14
 
15
+ friend: {
16
+ one: "1 Friend",
17
+ other: "%{count} Friends"
18
+ },
19
+
15
20
  page: {
16
21
  footer: "Footer",
17
22
  title: "Title",
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
9
+ - 3
10
+ version: 0.5.3
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-20 00:00:00 +02:00
18
+ date: 2011-09-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency