INNER CODE UNIT · TypeScript
detectLang
CronusL-1141/AI-company · dashboard/src/i18n/index.ts:12
function detectLang(): Lang {
// A cached effective language avoids a flash while the server preference loads.
// It is never sent back as an override, including the old manual browser value.
try {
const stored = localStorage.getItem('lang');
if (stored === 'zh' || stored === 'en') return stored;
} catch { /* Storage may be disabled; language settings still work via the API. */ }
const browserLang = navigator.language?.toLowerCase() || '';
if (browserLang.startsWith('zh')) return 'zh';
return 'en';
}
type LanguageSetting = {
mode: LanguageMode;
effective: Lang;
source: 'dashboard' | 'cc_settings' | 'codex' | 'system' | 'default';
};