Permalink
Browse files

fixed issue with objectTree replacement gets set on resStore ref inst…

…ead of own copy
  • Loading branch information...
jamuhl committed Feb 11, 2013
1 parent e5f43fe commit b6c5006fb6b74b1c8ad6ec4ed83e7b92ee30c093
@@ -893,10 +893,12 @@
'returned a object instead of string.';
f.log(value);
} else {
var copy = {};
for (var m in value) {
// apply translation on childs
value[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
}
value = copy;
}
}
found = value;
Binary file not shown.
@@ -889,10 +889,12 @@
'returned a object instead of string.';
f.log(value);
} else {
var copy = {};
for (var m in value) {
// apply translation on childs
value[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
}
value = copy;
}
}
found = value;
Binary file not shown.
@@ -890,10 +890,12 @@
'returned a object instead of string.';
f.log(value);
} else {
var copy = {};
for (var m in value) {
// apply translation on childs
value[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
}
value = copy;
}
}
found = value;
View
@@ -6,6 +6,7 @@
- fixed issue with posting missing when not using jquery
- post missing in correct lng if lng is given in translation options
- proper usage of deferred object in init function
- fixed issue replacing values in objectTree
### 1.5.10
- BREAKING: fixed plural rules for languages with extended plural forms (more than 2 forms)
@@ -71,19 +71,35 @@ describe('translation functionality', function() {
it('it should return objectTree applying options', function() {
expect(i18n.t('test', { replace: 'two' })).to.eql({ 'res': 'added two' });
expect(i18n.t('test', { replace: 'three' })).to.eql({ 'res': 'added three' });
expect(i18n.t('test', { replace: 'four' })).to.eql({ 'res': 'added four' });
});
});
describe('with flag in options', function() {
var resStore = {
dev: { translation: { } },
en: { translation: { } },
'en-US': {
translation: {
test: { res: 'added __replace__' }
}
}
};
beforeEach(function(done) {
i18n.init($.extend(opts, { returnObjectTrees: false }),
i18n.init($.extend(opts, {
returnObjectTrees: false,
resStore: resStore }),
function(t) { done(); } );
});
it('it should return objectTree', function() {
expect(i18n.t('test', { returnObjectTrees: true })).to.eql({ 'simple_en-US': 'ok_from_en-US' });
expect(i18n.t('test', { returnObjectTrees: true, replace: 'two' })).to.eql({ 'res': 'added two' });
expect(i18n.t('test', { returnObjectTrees: true, replace: 'three' })).to.eql({ 'res': 'added three' });
expect(i18n.t('test', { returnObjectTrees: true, replace: 'four' })).to.eql({ 'res': 'added four' });
});
});
View
@@ -134,10 +134,12 @@ function _translate(key, options){
'returned a object instead of string.';
f.log(value);
} else {
var copy = {}; // apply child translation on a copy
for (var m in value) {
// apply translation on childs
value[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options);
}
value = copy;
}
}
found = value;
View
@@ -775,19 +775,35 @@ describe('i18next', function() {
it('it should return objectTree applying options', function() {
expect(i18n.t('test', { replace: 'two' })).to.eql({ 'res': 'added two' });
expect(i18n.t('test', { replace: 'three' })).to.eql({ 'res': 'added three' });
expect(i18n.t('test', { replace: 'four' })).to.eql({ 'res': 'added four' });
});
});
describe('with flag in options', function() {
var resStore = {
dev: { translation: { } },
en: { translation: { } },
'en-US': {
translation: {
test: { res: 'added __replace__' }
}
}
};
beforeEach(function(done) {
i18n.init($.extend(opts, { returnObjectTrees: false }),
i18n.init($.extend(opts, {
returnObjectTrees: false,
resStore: resStore }),
function(t) { done(); } );
});
it('it should return objectTree', function() {
expect(i18n.t('test', { returnObjectTrees: true })).to.eql({ 'simple_en-US': 'ok_from_en-US' });
expect(i18n.t('test', { returnObjectTrees: true, replace: 'two' })).to.eql({ 'res': 'added two' });
expect(i18n.t('test', { returnObjectTrees: true, replace: 'three' })).to.eql({ 'res': 'added three' });
expect(i18n.t('test', { returnObjectTrees: true, replace: 'four' })).to.eql({ 'res': 'added four' });
});
});

0 comments on commit b6c5006

Please sign in to comment.