linshenkx/prompt-optimizer · warning · Error

Unsupported language: ${language}

Error message

Unsupported language: ${language}

What it means

Thrown by LanguageService.setLanguage when the passed language is not one of the supported built-in template languages. Validation is done via isValidLanguage(), so any string outside the built-in set (currently 'zh-CN' and 'en-US') is rejected before assignment.

Source

Thrown at packages/mcp-server/src/adapters/language-service.ts:37

      'en': 'en-US',
      'en-US': 'en-US',
      'english': 'en-US'
    };

    this.currentLanguage = languageMap[defaultLanguage as keyof typeof languageMap] || 'en-US';
  }

  async initialize(): Promise<void> {
    this.initialized = true;
  }

  async getCurrentLanguage(): Promise<BuiltinTemplateLanguage> {
    return this.currentLanguage;
  }

  async setLanguage(language: BuiltinTemplateLanguage): Promise<void> {
    if (!(await this.isValidLanguage(language))) {
      throw new Error(`Unsupported language: ${language}`);
    }
    this.currentLanguage = language;
  }

  async toggleLanguage(): Promise<BuiltinTemplateLanguage> {
    const newLanguage = this.currentLanguage === 'zh-CN' ? 'en-US' : 'zh-CN';
    await this.setLanguage(newLanguage);
    return newLanguage;
  }

  async isValidLanguage(language: string): Promise<boolean> {
    const supportedLanguages = await this.getSupportedLanguages();
    return supportedLanguages.includes(language as BuiltinTemplateLanguage);
  }

  async getSupportedLanguages(): Promise<BuiltinTemplateLanguage[]> {
    return ['en-US', 'zh-CN'];
  }

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Use only 'zh-CN' or 'en-US' — check the BowerTemplateLanguage/BuiltinTemplateLanguage type or listSupportedLanguages() for the exact set
  2. Map arbitrary user locales to the nearest supported one before calling setLanguage
  3. If you need another language, extend the built-in templates rather than passing an ad-hoc string

Example fix

// before
await svc.setLanguage(userLocale); // e.g. 'zh_CN' or 'fr-FR'

// after
const supported = ['zh-CN', 'en-US'] as const;
const lang = supported.includes(userLocale as any)
  ? (userLocale as typeof supported[number])
  : userLocale.startsWith('zh') ? 'zh-CN' : 'en-US';
await svc.setLanguage(lang);
Defensive patterns

Strategy: type-guard

Validate before calling

const SUPPORTED = ['zh-CN', 'en-US'] as const;
const lang = SUPPORTED.includes(reqLang as any) ? reqLang : 'en-US';
await svc.setLanguage(lang);

Type guard

const isBuiltinLanguage = (l: string): l is 'zh-CN' | 'en-US' =>
  l === 'zh-CN' || l === 'en-US';

Try / catch

try { await svc.setLanguage(lang); } catch { await svc.setLanguage('en-US'); }

Prevention

When it happens

Trigger: Calling setLanguage('zh_CN'), setLanguage('en'), setLanguage('fr-FR'), or any string not returned by the built-in language list; also calling toggleLanguage's underlying setLanguage with a value sourced from an unvalidated config or env var.

Common situations: Hardcoding a locale with the wrong format (underscore vs hyphen, missing region); passing a user's OS locale directly (navigator.language) without mapping it; adding a new language to config but not to the built-in template set.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/7eb406a50efe926e. Report an issue: GitHub.