Files
zn-ai/src/i18n/resolver.ts
DEV_DSW 79bea4f107 Refactor UUID generation, remove unused logger and encryption utilities, and clean up request handling
- Updated `generateUUID` function for improved readability and performance.
- Deleted `logger.ts`, `other.ts`, `request.ts`, `storage.ts`, `tansParams.ts`, and `validate.ts` as they were no longer needed.
- Simplified TypeScript configuration by removing unnecessary paths and aliases.
- Enhanced Vite configuration for better project structure and maintainability.
2026-04-17 15:38:08 +08:00

25 lines
874 B
TypeScript

import { SUPPORTED_LANGUAGE_CODES } from './constants';
import type { LanguageCode } from '../types/runtime';
const SUPPORTED_LANGUAGE_SET = new Set<string>(SUPPORTED_LANGUAGE_CODES);
export function normalizeLocale(locale: string | null | undefined): string {
return locale?.trim().toLowerCase().split('_').join('-') ?? '';
}
export function resolveSupportedLanguage(
locale: string | null | undefined,
fallback: LanguageCode = 'zh',
): LanguageCode {
const normalizedLocale = normalizeLocale(locale);
if (!normalizedLocale) return fallback;
const [baseLanguage] = normalizedLocale.split('-');
return SUPPORTED_LANGUAGE_SET.has(baseLanguage) ? (baseLanguage as LanguageCode) : fallback;
}
export function detectSystemLanguage(): LanguageCode {
if (typeof navigator === 'undefined') return 'zh';
return resolveSupportedLanguage(navigator.language);
}