Files
ProxMenux/AppImage/lib/i18n/languages.ts
T
MacRimi 5c33852a65 feat(i18n): add Swedish support + include Slovak in auto-fill defaults
Two related changes to the translation infrastructure:

1. Add Swedish (sv) as a supported locale in both the CLI and Monitor
   translation systems. Inspired by PR #121, which arrived before the
   current auto-generated cache layout existed.

2. Include Slovak (sk) in the default auto-fill target set. Guardrail #1
   in build_i18n_messages.py never overwrites a key whose target value
   differs from EN, so Vaso73's curated Slovak strings stay intact —
   auto-translation only fills keys that are still on the English
   fallback. Trade-off accepted: sk users see decent machine translation
   for new keys immediately instead of raw English while human curation
   catches up, and Vaso73 keeps full ownership of the wording via
   follow-up PRs.

Changes:
- AppImage/lib/i18n/languages.ts: add "sv" to LanguageCode + register
  in SUPPORTED_LANGUAGES.
- AppImage/messages/sv/common.json: stub — will be filled by the i18n
  workflow on the local bootstrap.
- .github/scripts/build_translation_cache.py: add "sv" to
  DEFAULT_LANGUAGES.
- .github/scripts/build_i18n_messages.py: add "sk" and "sv" to
  DEFAULT_LANGUAGES; update comments to explain the sk decision.
- .github/workflows/build-i18n-messages.yml: default input includes
  sk + sv; comments updated to match.
2026-08-09 10:35:03 +02:00

41 lines
1.7 KiB
TypeScript

export const LANGUAGE_STORAGE_KEY = "proxmenux-ui-language"
export const DEFAULT_LANGUAGE = "en"
export type LanguageCode = "en" | "es" | "fr" | "de" | "it" | "pt" | "sk" | "sv"
export type LanguageStatus = "complete" | "partial" | "needs-translation"
export interface SupportedLanguage {
code: LanguageCode
englishName: string
nativeName: string
status: LanguageStatus
}
export const SUPPORTED_LANGUAGES: SupportedLanguage[] = [
{ code: "en", englishName: "English", nativeName: "English", status: "complete" },
{ code: "sk", englishName: "Slovak", nativeName: "Slovenčina", status: "complete" },
{ code: "es", englishName: "Spanish", nativeName: "Español", status: "needs-translation" },
{ code: "fr", englishName: "French", nativeName: "Français", status: "needs-translation" },
{ code: "de", englishName: "German", nativeName: "Deutsch", status: "needs-translation" },
{ code: "it", englishName: "Italian", nativeName: "Italiano", status: "needs-translation" },
{ code: "pt", englishName: "Portuguese", nativeName: "Português", status: "needs-translation" },
{ code: "sv", englishName: "Swedish", nativeName: "Svenska", status: "needs-translation" },
]
export function isSupportedLanguage(value: string | null | undefined): value is LanguageCode {
return SUPPORTED_LANGUAGES.some((language) => language.code === value)
}
export function detectBrowserLanguage(): LanguageCode {
if (typeof navigator === "undefined") return DEFAULT_LANGUAGE
const candidates = [navigator.language, ...(navigator.languages || [])]
for (const candidate of candidates) {
const code = candidate?.split("-")[0]?.toLowerCase()
if (isSupportedLanguage(code)) return code
}
return DEFAULT_LANGUAGE
}