Skip to content
Closed
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
16 changes: 13 additions & 3 deletions packages/platform/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Messages = Record<string, IntlString | Record<string, IntlString>>
const loaders = new Map<Plugin, Loader>()
const translations = new Map<Plugin, Messages | Status>()
const cache = new Map<IntlString, IntlMessageFormat | Status>()
const ENGLISH_LOCALE = 'en'

/**
* @public
Expand Down Expand Up @@ -91,9 +92,18 @@ async function getTranslation (id: _IdInfo, locale: string): Promise<IntlString
if (messages instanceof Status) {
return messages
}
return id.kind !== undefined
? (messages[id.kind] as Record<string, IntlString>)?.[id.name]
: (messages[id.name] as IntlString)
if (id.kind !== undefined) {
if ((messages[id.kind] as Record<string, IntlString>)?.[id.name] !== undefined) {
return (messages[id.kind] as Record<string, IntlString>)?.[id.name]
} else {
const englishMessages = await loadTranslationsForComponent(id.component, ENGLISH_LOCALE)
if (!(englishMessages instanceof Status)) {
return (englishMessages[id.kind] as Record<string, IntlString>)?.[id.name]
}
}
} else {
return messages[id.name] as IntlString
}
} catch (err) {
const status = unknownError(err)
await setPlatformStatus(status)
Expand Down