Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed english not used by default when other translation is not found #5966

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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