fix(i18n): fallback to server locale for "Default" user lang in notifs (#3190)

This commit is contained in:
fallenbagel
2026-06-23 17:07:34 +08:00
committed by GitHub
parent 0a1f7035d0
commit ef9edc832f

View File

@@ -1,4 +1,5 @@
import { createIntl, createIntlCache } from '@formatjs/intl';
import { getSettings } from '@server/lib/settings';
import type { AvailableLocale } from '@server/types/languages';
import { availableLocales } from '@server/types/languages';
import fs from 'fs';
@@ -38,7 +39,10 @@ export function initI18n(): void {
}
export function getIntl(locale?: AvailableLocale): IntlInstance {
return intls.get(locale ?? 'en') || intls.get('en')!;
// "Default" stores a falsy locale, so fall back to the server language, then English
const serverLocale = getSettings().main.locale as AvailableLocale;
const resolved = locale || serverLocale || 'en';
return intls.get(resolved) || intls.get('en')!;
}
type MessageDescriptorMap<T extends Record<string, string>> = {