fix(i18n): stop repairCatalog crashing on un-bootstrapped locale keys (#11728)

en.json carries ~190 keys per locale that the locale catalogs have not been
bootstrapped with yet, so every repair-locale-catalog run threw a TypeError
before doing any work. Skip missing leaves instead.

Split out of #11728 so the crash fix can land without the catalog
regeneration, which still needs native-speaker review.

Co-authored-by: Turtle-Hwan <turtlehwan@gmail.com>

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Turtle-Hwan 2026-08-04 02:04:47 -07:00 committed by Neil
parent aa001101f2
commit f9a5920954
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest'
import { repairCatalog } from './locale-translation-policy.mjs'
// Regression: en.json routinely carries keys a locale catalog has not been bootstrapped with yet
// (~190 per locale at the time of writing), which crashed the whole repair run before it did any work.
describe('repairCatalog with un-bootstrapped keys', () => {
const enCatalog = {
auto: {
lib: { agent: { catalog: { '760bc6883d': 'Codex' } } },
components: { untranslated: 'Continue', nested: { alsoMissing: 'Refresh' } }
}
}
const translatedOnly = () => ({ auto: { lib: { agent: { catalog: { '760bc6883d': '사본' } } } } })
it('skips leaves the locale catalog is missing instead of throwing', () => {
for (const locale of ['ko', 'ja', 'zh', 'es']) {
const localeCatalog = translatedOnly()
expect(() => repairCatalog(enCatalog, localeCatalog, locale), locale).not.toThrow()
expect(localeCatalog.auto.components, locale).toBeUndefined()
}
})
it('still repairs the leaves that are present', () => {
const localeCatalog = translatedOnly()
expect(repairCatalog(enCatalog, localeCatalog, 'ko')).toBe(1)
expect(localeCatalog.auto.lib.agent.catalog['760bc6883d']).toBe('Codex')
})
})

View File

@ -551,6 +551,11 @@ export function repairCatalog(enCatalog, localeCatalog, locale) {
for (const leaf of leaves) {
const current = leaf.key.split('.').reduce((cursor, part) => cursor?.[part], localeCatalog)
// Why: en.json carries keys the locale catalog has not been bootstrapped with yet; repair only
// rewrites values that already exist, so skip instead of crashing on undefined.
if (typeof current !== 'string') {
continue
}
const next = repairTranslatedValue({
key: leaf.key,
enValue: leaf.value,