Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added #33: config option 'defaultLocale'

  • Loading branch information...
commit 48de52c7e52e85b442d8aa9e25682c398e58374d 1 parent b7bb6dc
@mashpie authored
View
5 README.md
@@ -47,6 +47,9 @@ Minimal example, just setup two locales
// setup some locales - other locales default to en silently
locales:['en', 'de'],
+ // you may alter a site wide default locale
+ defaultLocale: 'de',
+
// sets a custom cookie name to parse locale settings from
cookie: 'yourcookiename',
@@ -214,7 +217,7 @@ remember to turn off automatic locale file updates:
## Changelog
-* 0.3.8: fixed: #44, #49; merged: #47, #45, #50; updated: README
+* 0.3.8: fixed: #44, #49; merged: #47, #45, #50; added: #33; updated: README
* 0.3.7: tests by mocha.js, added `this.locale` to `__` and `__n`
* 0.3.6: travisCI, writeFileSync, devDependencies, jslint, MIT, fixed: #29, #9, merged: #25, #30, #43
* 0.3.5: fixed some issues, prepared refactoring, prepared publishing to npm finally
View
12 i18n.js
@@ -27,6 +27,7 @@ var i18n = exports;
i18n.version = '0.3.8';
i18n.configure = function (opt) {
+
// you may register helpers in global scope, up to you
if (typeof opt.register === 'object') {
opt.register.__ = i18n.__;
@@ -56,6 +57,11 @@ i18n.configure = function (opt) {
extension = opt.extension;
}
+ // setting defaultLocale
+ if (typeof opt.defaultLocale === 'string') {
+ defaultLocale = opt.defaultLocale;
+ }
+
// enabled some debug output
if (opt.debug) {
debug = opt.debug;
@@ -149,10 +155,10 @@ i18n.setLocale = function (arg1, arg2) {
};
i18n.getLocale = function (request) {
- if (request === undefined) {
- return defaultLocale;
+ if (request && request.locale) {
+ return request.locale;
}
- return request.locale;
+ return defaultLocale;
};
i18n.overrideLocaleFromQuery = function (req) {
View
1  test/i18n.configure.js
@@ -11,6 +11,7 @@ describe('Configuration settings:', function () {
beforeEach(function () {
i18n.configure({
locales: ['en', 'de'],
+ defaultLocale: 'en',
register: testScope,
directory: './testlocales',
extension: '.json',
View
3  test/i18n.test.js
@@ -5,7 +5,8 @@ var i18n = require('../i18n'),
i18n.configure({
locales: ['en', 'de'],
- register: global
+ register: global,
+ defaultLocale: 'en'
});
Please sign in to comment.
Something went wrong with that request. Please try again.