diff --git a/index.js b/index.js index 31cb4a95e4..05d0de9f21 100644 --- a/index.js +++ b/index.js @@ -105,7 +105,8 @@ module.exports = class Items extends Array { if (this.options.i18n) { // only insert i18n for the objects we're inserting, so we don't bloat memory if (Array.isArray(this.options.i18n)) { - const raw = i18n[item.uniqueName]; + const itemI18n = i18n[item.uniqueName]; + const raw = itemI18n ? { ...itemI18n } : undefined; // only process if passed language is a supported i18n value if (raw) { Object.keys(raw).forEach((locale) => { diff --git a/index.mjs b/index.mjs index 817d4d073a..41a1426a0e 100644 --- a/index.mjs +++ b/index.mjs @@ -104,7 +104,8 @@ export default class Items extends Array { if (this.options.i18n) { // only insert i18n for the objects we're inserting so we don't bloat memory if (Array.isArray(this.options.i18n)) { - const raw = i18n[item.uniqueName]; + const itemI18n = i18n[item.uniqueName]; + const raw = itemI18n ? { ...itemI18n } : undefined; // only process if passed language is a supported i18n value if (raw) { Object.keys(raw).forEach((locale) => { diff --git a/test/index.spec.mjs b/test/index.spec.mjs index 74d00507a0..ad81fee497 100755 --- a/test/index.spec.mjs +++ b/test/index.spec.mjs @@ -124,6 +124,18 @@ const test = (base) => { assert(!!items[0].i18n.es); assert(!items.i18n); }); + it('should have i18n on object for different locales in same runtime', async () => { + const getItem = async (locale) => { + const items = await wrapConstr({ category: ['Pets'], i18n: [locale], i18nOnObject: true }); + const firstItem = items[0]; + return firstItem?.i18n; + }; + + const esI18n = await getItem('es'); + assert.ok(esI18n.es, 'should have i18n on object for es'); + const jaI18n = await getItem('ja'); + assert.ok(jaI18n.ja, 'should have i18n on object for ja'); + }); }); describe('drops', () => { beforeEach(gc);