Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +108 to +109
Copy link
Copy Markdown
Member

@AyAyEm AyAyEm Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other value besides an object or undefined itemI18n might be so it needs this check?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None, but without that verification the branch coverage percentage requires a test that cannot be done on the if statement of line 111

// only process if passed language is a supported i18n value
if (raw) {
Object.keys(raw).forEach((locale) => {
Expand Down
3 changes: 2 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
12 changes: 12 additions & 0 deletions test/index.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading