Skip to content

Commit

Permalink
feat: non-breaking error log for nested key exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Trung Dang committed Dec 7, 2023
1 parent 405e846 commit b175a62
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,18 @@ function transformToI18n(array: Record<any, any>[], key: string, value: string,
array.forEach((item) => {
const k = oGet(item, key)
const v = oGet(item, value)
if (keyStyle === 'nested')
oSet(obj, k, v)
else
obj[k] = v
if (keyStyle === 'nested') {
try {
oSet(obj, k, v)
}
catch (error) {
if (error instanceof TypeError && error.message.match(/^Cannot create property '.+'? on string/))
return logger.error(`[sheetI18n] nested key exist: '${k}', consider using flat keyStyle.`)

throw error
}
}
else { obj[ka] = v }
})

return obj
Expand Down

0 comments on commit b175a62

Please sign in to comment.