fix: i18n string problems (#6131)

* fix: apply non-json i18n fixes

* fix: pruning

* fix: prepr

* fix: run.mjs

* fix: lint
This commit is contained in:
Calum H.
2026-05-29 16:55:39 +01:00
committed by GitHub
parent 5c1ffd9ff2
commit 047b8c3bf7
165 changed files with 1283 additions and 5626 deletions
+27 -14
View File
@@ -35,6 +35,25 @@ function findLocaleLoader(modules: LocaleModules, code: string) {
return undefined
}
function formatIcuMessage(msg: string, locale: string, values: Record<string, unknown>) {
const cacheKey = `${locale}:${msg}`
let formatter = formatterCache.get(cacheKey)
try {
if (!formatter) {
formatter = new IntlMessageFormat(msg, locale)
formatterCache.set(cacheKey, formatter)
}
const result = formatter.format(values)
if (import.meta.dev && typeof result !== 'string') {
debug('formatIcuMessage: format returned non-string', typeof result)
}
return result as string
} catch {
return null
}
}
async function loadLocale(code: string): Promise<void> {
if (messageCache.has(code)) {
debug('loadLocale: already cached', code)
@@ -148,21 +167,15 @@ export default defineNuxtPlugin({
if (!values || Object.keys(values).length === 0) return msg
const cacheKey = `${currentLocale}:${msg}`
let formatter = formatterCache.get(cacheKey)
if (!formatter) {
formatter = new IntlMessageFormat(msg, currentLocale)
formatterCache.set(cacheKey, formatter)
}
try {
const result = formatter.format(values) as string
if (import.meta.dev && typeof result !== 'string') {
debug('t: format returned non-string', key, typeof result)
}
return result
} catch {
return msg
const formatted = formatIcuMessage(msg, currentLocale, values)
if (formatted !== null) return formatted
const fallbackMsg = fallbackMessages?.[key]
if (fallbackMsg && fallbackMsg !== msg) {
return formatIcuMessage(fallbackMsg, DEFAULT_LOCALE, values) ?? fallbackMsg
}
return msg
}
async function setLocale(newLocale: string): Promise<void> {