Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added option to have falback lookup to default namespace

  • Loading branch information...
commit 9383a2a42686e1f583c493846c4cc4d183f88afd 1 parent 56cef66
@jamuhl jamuhl authored
View
5 release/i18next-1.5.11pre.js
@@ -69,6 +69,7 @@
fallbackLng: 'dev',
detectLngQS: 'setLng',
ns: 'translation',
+ fallbackToDefaultNS: false,
nsseparator: ':',
keyseparator: '.',
selectorAttr: 'data-i18n',
@@ -889,6 +890,10 @@
found = value;
}
}
+
+ if (found === undefined && o.fallbackToDefaultNS) {
+ found = _translate(key, options);
+ }
if (found === undefined && o.sendMissing) {
if (options.lng) {
View
BIN  release/i18next-1.5.11pre.zip
Binary file not shown
View
5 release/i18next.amd-1.5.11pre.js
@@ -65,6 +65,7 @@
fallbackLng: 'dev',
detectLngQS: 'setLng',
ns: 'translation',
+ fallbackToDefaultNS: false,
nsseparator: ':',
keyseparator: '.',
selectorAttr: 'data-i18n',
@@ -885,6 +886,10 @@
found = value;
}
}
+
+ if (found === undefined && o.fallbackToDefaultNS) {
+ found = _translate(key, options);
+ }
if (found === undefined && o.sendMissing) {
if (options.lng) {
View
BIN  release/i18next.amd-1.5.11pre.zip
Binary file not shown
View
5 release/i18next.amd.withJQuery-1.5.11pre.js
@@ -66,6 +66,7 @@
fallbackLng: 'dev',
detectLngQS: 'setLng',
ns: 'translation',
+ fallbackToDefaultNS: false,
nsseparator: ':',
keyseparator: '.',
selectorAttr: 'data-i18n',
@@ -886,6 +887,10 @@
found = value;
}
}
+
+ if (found === undefined && o.fallbackToDefaultNS) {
+ found = _translate(key, options);
+ }
if (found === undefined && o.sendMissing) {
if (options.lng) {
View
24 spec/init.spec.js
@@ -249,6 +249,30 @@ describe('Initialisation', function() {
expect(i18n.t('simple_dev', { ns: 'ns.common' })).to.be('ok_from_common_dev');
});
+ describe('and fallbacking to default namespace', function() {
+ var resStore = {
+ dev: { 'ns.special': { 'simple_dev': 'ok_from_dev' } },
+ en: { 'ns.special': { 'simple_en': 'ok_from_en' } },
+ 'en-US': { 'ns.special': { 'simple_en-US': 'ok_from_en-US' } }
+ };
+
+ beforeEach(function(done) {
+ i18n.init( $.extend(opts, {
+ fallbackToDefaultNS: true,
+ resStore: resStore,
+ ns: { namespaces: ['ns.common', 'ns.special'], defaultNs: 'ns.special'} } ),
+ function(t) { done(); });
+ });
+
+ it('it should fallback to default ns', function() {
+ // default ns fallback lookup
+ expect(i18n.t('ns.common:simple_en-US')).to.be('ok_from_en-US');
+ expect(i18n.t('ns.common:simple_en')).to.be('ok_from_en');
+ expect(i18n.t('ns.common:simple_dev')).to.be('ok_from_dev');
+ });
+
+ });
+
});
describe('with reloading additional namespace', function() {
View
1  spec/spec.js
@@ -11,6 +11,7 @@ describe('i18next', function() {
preload: [],
lowerCaseLng: false,
ns: 'translation',
+ fallbackToDefaultNS: false,
resGetPath: 'locales/__lng__/__ns__.json',
dynamicLoad: false,
useLocalStorage: false,
View
1  src/i18next.defaults.js
@@ -8,6 +8,7 @@ var o = {
fallbackLng: 'dev',
detectLngQS: 'setLng',
ns: 'translation',
+ fallbackToDefaultNS: false,
nsseparator: ':',
keyseparator: '.',
selectorAttr: 'data-i18n',
View
4 src/i18next.translate.js
@@ -143,6 +143,10 @@ function _translate(key, options){
found = value;
}
}
+
+ if (found === undefined && o.fallbackToDefaultNS) {
+ found = _translate(key, options);
+ }
if (found === undefined && o.sendMissing) {
if (options.lng) {
View
25 test/test.js
@@ -11,6 +11,7 @@ describe('i18next', function() {
preload: [],
lowerCaseLng: false,
ns: 'translation',
+ fallbackToDefaultNS: false,
resGetPath: 'locales/__lng__/__ns__.json',
dynamicLoad: false,
useLocalStorage: false,
@@ -278,6 +279,30 @@ describe('i18next', function() {
expect(i18n.t('simple_dev', { ns: 'ns.common' })).to.be('ok_from_common_dev');
});
+ describe('and fallbacking to default namespace', function() {
+ var resStore = {
+ dev: { 'ns.special': { 'simple_dev': 'ok_from_dev' } },
+ en: { 'ns.special': { 'simple_en': 'ok_from_en' } },
+ 'en-US': { 'ns.special': { 'simple_en-US': 'ok_from_en-US' } }
+ };
+
+ beforeEach(function(done) {
+ i18n.init( $.extend(opts, {
+ fallbackToDefaultNS: true,
+ resStore: resStore,
+ ns: { namespaces: ['ns.common', 'ns.special'], defaultNs: 'ns.special'} } ),
+ function(t) { done(); });
+ });
+
+ it('it should fallback to default ns', function() {
+ // default ns fallback lookup
+ expect(i18n.t('ns.common:simple_en-US')).to.be('ok_from_en-US');
+ expect(i18n.t('ns.common:simple_en')).to.be('ok_from_en');
+ expect(i18n.t('ns.common:simple_dev')).to.be('ok_from_dev');
+ });
+
+ });
+
});
describe('with reloading additional namespace', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.