Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow locale per-instance + local override in i18n

  • Loading branch information...
commit 4486e49c519c56662b8fe404b6c944effb1291f6 1 parent a15bd5e
Matthew Eernisse authored

Showing 1 changed file with 16 additions and 3 deletions. Show diff stats Hide diff stats

  1. 19  lib/i18n.js
19  lib/i18n.js
@@ -18,8 +18,10 @@
18 18
 var core = require('./core')
19 19
   , i18n;
20 20
 
  21
+var DEFAULT_LOCALE = 'en-us';
  22
+
21 23
 i18n = new (function () {
22  
-  var _defaultLocale = 'en-us'
  24
+  var _defaultLocale = DEFAULT_LOCALE
23 25
     , _strings = {};
24 26
 
25 27
   this.getText = function (key, opts, locale) {
@@ -50,8 +52,19 @@ i18n = new (function () {
50 52
 })();
51 53
 
52 54
 i18n.I18n = function (locale) {
53  
-  this.getText = function (key, opts) {
54  
-    return i18n.getText(key, opts || {}, locale);
  55
+  var _locale = locale || DEFAULT_LOCALE;
  56
+
  57
+  this.getLocale = function (locale) {
  58
+    return _locale;
  59
+  };
  60
+
  61
+  this.setLocale = function (locale) {
  62
+    _locale = locale;
  63
+  };
  64
+
  65
+  this.getText = function (key, opts, locale) {
  66
+    return i18n.getText(key,
  67
+        opts || {}, locale || _locale);
55 68
   };
56 69
   this.t = this.getText;
57 70
 };

0 notes on commit 4486e49

Please sign in to comment.
Something went wrong with that request. Please try again.