fix(i18n): handle POSIX locale values in getLocale(), closes #3518 (#3522)

When LANG=C.UTF-8, navigator.language can return 'C' which is not a
valid BCP 47 tag, causing Intl.NumberFormat and toLocaleString to throw.
Normalize POSIX values (C, C.UTF-8, POSIX) to 'en-US' at the source.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Huang Xin
2026-03-12 23:36:48 +08:00
committed by GitHub
parent 7a605a357a
commit 9b53ccc9de
2 changed files with 9 additions and 4 deletions
+5 -1
View File
@@ -32,7 +32,11 @@ export const makeSafeFilename = (filename: string, replacement = '_') => {
};
export const getLocale = () => {
return localStorage?.getItem('i18nextLng') || navigator?.language || '';
const locale = localStorage?.getItem('i18nextLng') || navigator?.language || '';
// POSIX locale values (e.g. 'C', 'C.UTF-8', 'POSIX') are not valid BCP 47
// tags and would cause Intl/toLocaleString to throw — fall back to en-US
if (!locale || /^(C|POSIX)(\..*)?$/i.test(locale)) return 'en-US';
return locale;
};
export const getUserLang = () => {