mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 07:10:55 +00:00
Auto-detect LLM output language from system locale on first startup
This commit is contained in:
parent
a92be72e88
commit
4d9f25e9fe
5 changed files with 259 additions and 1 deletions
|
|
@ -46,17 +46,27 @@ const getLocalePath = (
|
|||
return path.join(baseDir, `${lang}.js`);
|
||||
};
|
||||
|
||||
// Supported locale codes mapped to English language names
|
||||
const LOCALE_TO_LANGUAGE_NAME: Record<string, string> = {
|
||||
zh: 'Chinese',
|
||||
en: 'English',
|
||||
ru: 'Russian',
|
||||
de: 'German',
|
||||
};
|
||||
|
||||
// Language detection
|
||||
export function detectSystemLanguage(): SupportedLanguage {
|
||||
const envLang = process.env['QWEN_CODE_LANG'] || process.env['LANG'];
|
||||
if (envLang?.startsWith('zh')) return 'zh';
|
||||
if (envLang?.startsWith('en')) return 'en';
|
||||
if (envLang?.startsWith('ru')) return 'ru';
|
||||
if (envLang?.startsWith('de')) return 'de';
|
||||
|
||||
try {
|
||||
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
|
||||
if (locale.startsWith('zh')) return 'zh';
|
||||
if (locale.startsWith('ru')) return 'ru';
|
||||
if (locale.startsWith('de')) return 'de';
|
||||
} catch {
|
||||
// Fallback to default
|
||||
}
|
||||
|
|
@ -64,6 +74,14 @@ export function detectSystemLanguage(): SupportedLanguage {
|
|||
return 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a locale code to its English language name.
|
||||
* Used for LLM output language instructions.
|
||||
*/
|
||||
export function getLanguageNameFromLocale(locale: SupportedLanguage): string {
|
||||
return LOCALE_TO_LANGUAGE_NAME[locale] || 'English';
|
||||
}
|
||||
|
||||
// Translation loading
|
||||
async function loadTranslationsAsync(
|
||||
lang: SupportedLanguage,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue