Permalink
Browse files

Allow locale per-instance + local override in i18n

  • Loading branch information...
1 parent a15bd5e commit 4486e49c519c56662b8fe404b6c944effb1291f6 @mde committed Jun 23, 2013
Showing with 16 additions and 3 deletions.
  1. +16 −3 lib/i18n.js
View
@@ -18,8 +18,10 @@
var core = require('./core')
, i18n;
+var DEFAULT_LOCALE = 'en-us';
+
i18n = new (function () {
- var _defaultLocale = 'en-us'
+ var _defaultLocale = DEFAULT_LOCALE
, _strings = {};
this.getText = function (key, opts, locale) {
@@ -50,8 +52,19 @@ i18n = new (function () {
})();
i18n.I18n = function (locale) {
- this.getText = function (key, opts) {
- return i18n.getText(key, opts || {}, locale);
+ var _locale = locale || DEFAULT_LOCALE;
+
+ this.getLocale = function (locale) {
+ return _locale;
+ };
+
+ this.setLocale = function (locale) {
+ _locale = locale;
+ };
+
+ this.getText = function (key, opts, locale) {
+ return i18n.getText(key,
+ opts || {}, locale || _locale);
};
this.t = this.getText;
};

0 comments on commit 4486e49

Please sign in to comment.