Skip to content

Commit

Permalink
fix(core): handle null as i18n removal, close koishijs#1069
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 8, 2023
1 parent 77068bb commit 90bb493
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export class I18n {
}

private* set(locale: string, prefix: string, value: I18n.Node): Generator<string> {
if (prefix.includes('@') || typeof value === 'string') {
if (typeof value === 'object' && value && !prefix.includes('@')) {
for (const key in value) {
yield* this.set(locale, prefix + key + '.', value[key])
}
} else if (prefix.includes('@') || typeof value === 'string') {
const dict = this._data[locale]
const [path, preset] = prefix.slice(0, -1).split('@')
if (preset) {
Expand All @@ -79,9 +83,7 @@ export class I18n {
dict[path] = value
yield path
} else {
for (const key in value) {
yield* this.set(locale, prefix + key + '.', value[key])
}
delete this._data[locale][prefix.slice(0, -1)]
}
}

Expand Down

0 comments on commit 90bb493

Please sign in to comment.