Permalink
Browse files

function to add resources after init

  • Loading branch information...
1 parent f813d80 commit e5f43fef0e5bfd82cfed1a18ff1ec1cfde4592b3 @jamuhl jamuhl committed Feb 11, 2013
View
13 release/i18next-1.5.11pre.js
@@ -600,6 +600,18 @@
return init(cb);
}
+ function addResourceBundle(lng, ns, resources) {
+ if (typeof ns !== 'string') {
+ resources = ns;
+ ns = o.ns.defaultNs;
+ }
+
+ resStore[lng] = resStore[lng] || {};
+ resStore[lng][ns] = resStore[lng][ns] || {};
+
+ f.extend(resStore[lng][ns], resources);
+ }
+
function setDefaultNamespace(ns) {
o.ns.defaultNs = ns;
}
@@ -2379,6 +2391,7 @@
i18n.init = init;
i18n.setLng = setLng;
i18n.preload = preload;
+ i18n.addResourceBundle = addResourceBundle;
i18n.loadNamespace = loadNamespace;
i18n.loadNamespaces = loadNamespaces;
i18n.setDefaultNamespace = setDefaultNamespace;
View
BIN release/i18next-1.5.11pre.zip
Binary file not shown.
View
13 release/i18next.amd-1.5.11pre.js
@@ -596,6 +596,18 @@
return init(cb);
}
+ function addResourceBundle(lng, ns, resources) {
+ if (typeof ns !== 'string') {
+ resources = ns;
+ ns = o.ns.defaultNs;
+ }
+
+ resStore[lng] = resStore[lng] || {};
+ resStore[lng][ns] = resStore[lng][ns] || {};
+
+ f.extend(resStore[lng][ns], resources);
+ }
+
function setDefaultNamespace(ns) {
o.ns.defaultNs = ns;
}
@@ -2375,6 +2387,7 @@
i18n.init = init;
i18n.setLng = setLng;
i18n.preload = preload;
+ i18n.addResourceBundle = addResourceBundle;
i18n.loadNamespace = loadNamespace;
i18n.loadNamespaces = loadNamespaces;
i18n.setDefaultNamespace = setDefaultNamespace;
View
BIN release/i18next.amd-1.5.11pre.zip
Binary file not shown.
View
13 release/i18next.amd.withJQuery-1.5.11pre.js
@@ -597,6 +597,18 @@
return init(cb);
}
+ function addResourceBundle(lng, ns, resources) {
+ if (typeof ns !== 'string') {
+ resources = ns;
+ ns = o.ns.defaultNs;
+ }
+
+ resStore[lng] = resStore[lng] || {};
+ resStore[lng][ns] = resStore[lng][ns] || {};
+
+ f.extend(resStore[lng][ns], resources);
+ }
+
function setDefaultNamespace(ns) {
o.ns.defaultNs = ns;
}
@@ -2376,6 +2388,7 @@
i18n.init = init;
i18n.setLng = setLng;
i18n.preload = preload;
+ i18n.addResourceBundle = addResourceBundle;
i18n.loadNamespace = loadNamespace;
i18n.loadNamespaces = loadNamespaces;
i18n.setDefaultNamespace = setDefaultNamespace;
View
1 releasenotes.md
@@ -1,4 +1,5 @@
### 1.5.11pre
+- function to add resources after init
- option to lookup in default namespace if value is not found in given namespace
- option to change interpolation prefix and suffix via translation options
- fixed issue with using ns/keyseparator on plurals, context,...
View
24 spec/init.spec.js
@@ -70,6 +70,30 @@ describe('Initialisation', function() {
describe('advanced initialisation options', function() {
+ describe('adding resources after init', function() {
+
+ var resStore = {
+ dev: { translation: { 'simple_dev': 'ok_from_dev' } },
+ en: { translation: { 'simple_en': 'ok_from_en' } }//,
+ //'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } }
+ };
+
+ beforeEach(function(done) {
+ i18n.init( $.extend(opts, { resStore: resStore }),
+ function(t) {
+ i18n.addResourceBundle('en-US', 'translation', { 'simple_en-US': 'ok_from_en-US' });
+ done();
+ });
+ });
+
+ it('it should provide passed in resources for translation', function() {
+ expect(i18n.t('simple_en-US')).to.be('ok_from_en-US');
+ expect(i18n.t('simple_en')).to.be('ok_from_en');
+ expect(i18n.t('simple_dev')).to.be('ok_from_dev');
+ });
+
+ });
+
describe('setting load', function() {
describe('to current', function() {
View
1 src/i18next.api.js
@@ -2,6 +2,7 @@
i18n.init = init;
i18n.setLng = setLng;
i18n.preload = preload;
+i18n.addResourceBundle = addResourceBundle;
i18n.loadNamespace = loadNamespace;
i18n.loadNamespaces = loadNamespaces;
i18n.setDefaultNamespace = setDefaultNamespace;
View
12 src/i18next.functions.js
@@ -8,6 +8,18 @@ function preload(lngs, cb) {
return init(cb);
}
+function addResourceBundle(lng, ns, resources) {
+ if (typeof ns !== 'string') {
+ resources = ns;
+ ns = o.ns.defaultNs;
+ }
+
+ resStore[lng] = resStore[lng] || {};
+ resStore[lng][ns] = resStore[lng][ns] || {};
+
+ f.extend(resStore[lng][ns], resources);
+}
+
function setDefaultNamespace(ns) {
o.ns.defaultNs = ns;
}
View
24 test/test.js
@@ -100,6 +100,30 @@ describe('i18next', function() {
describe('advanced initialisation options', function() {
+ describe('adding resources after init', function() {
+
+ var resStore = {
+ dev: { translation: { 'simple_dev': 'ok_from_dev' } },
+ en: { translation: { 'simple_en': 'ok_from_en' } }//,
+ //'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } }
+ };
+
+ beforeEach(function(done) {
+ i18n.init( $.extend(opts, { resStore: resStore }),
+ function(t) {
+ i18n.addResourceBundle('en-US', 'translation', { 'simple_en-US': 'ok_from_en-US' });
+ done();
+ });
+ });
+
+ it('it should provide passed in resources for translation', function() {
+ expect(i18n.t('simple_en-US')).to.be('ok_from_en-US');
+ expect(i18n.t('simple_en')).to.be('ok_from_en');
+ expect(i18n.t('simple_dev')).to.be('ok_from_dev');
+ });
+
+ });
+
describe('setting load', function() {
describe('to current', function() {

0 comments on commit e5f43fe

Please sign in to comment.