A free, open source, and extensible speech-to-text application that works completely offline.
fix 'no' not showing up + add ci so shouldnt happen again (#2001)
CJ Pais6fa850612e12
diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.ymlindex 68782217..6dbcc221 100644--- a/.github/workflows/code-quality.yml+++ b/.github/workflows/code-quality.yml@@ -5,6 +5,8 @@ on:branches: [main]paths:- "src/**"+ - "src-tauri/src/catalog/catalog.json"+ - "scripts/**"- "package.json"- "bun.lock"- ".eslintrc*"@@ -16,6 +18,8 @@ on:pull_request:paths:- "src/**"+ - "src-tauri/src/catalog/catalog.json"+ - "scripts/**"- "package.json"- "bun.lock"- ".eslintrc*"@@ -45,6 +49,9 @@ jobs:- name: Check translation consistencyrun: bun run check:translations+ - name: Check model language coverage+ run: bun run check:model-languages+- name: Run ESLintrun: bun run lintdiff --git a/package.json b/package.jsonindex f391d397..7cbb37f4 100644--- a/package.json+++ b/package.json@@ -17,6 +17,7 @@"test:playwright": "playwright test","test:playwright:ui": "playwright test --ui","check:translations": "bun scripts/check-translations.ts",+ "check:model-languages": "bun scripts/check-model-language-coverage.ts","postinstall": "bun scripts/check-nix-deps.ts"},"dependencies": {diff --git a/scripts/check-model-language-coverage.ts b/scripts/check-model-language-coverage.tsnew file mode 100644index 00000000..9387682c--- /dev/null+++ b/scripts/check-model-language-coverage.ts@@ -0,0 +1,52 @@+import catalog from "../src-tauri/src/catalog/catalog.json";+import {+ MODEL_CAPABILITY_LANGUAGES,+ supportsLanguageCode,+} from "../src/lib/constants/languages.ts";++interface CatalogModel {+ name: string;+ languages?: string[];+}++const failures: string[] = [];++// These model-code variants intentionally share one persisted UI intent. Keep+// this assertion beside catalog coverage so adding a separate picker entry+// cannot silently break language continuity when users switch model families.+if (+ !supportsLanguageCode(["nb"], "no") ||+ !supportsLanguageCode(["no"], "nb")+) {+ failures.push(+ "Norwegian intent `no` must remain equivalent to model code `nb`",+ );+}++for (const model of catalog.models as CatalogModel[]) {+ for (const modelLanguage of model.languages ?? []) {+ const matchingIntents = MODEL_CAPABILITY_LANGUAGES.filter((language) =>+ supportsLanguageCode([modelLanguage], language.value),+ );++ if (matchingIntents.length !== 1) {+ const matchSummary =+ matchingIntents.length === 0+ ? "no frontend language intent"+ : `ambiguous intents: ${matchingIntents+ .map((language) => language.value)+ .join(", ")}`;+ failures.push(`${model.name}: ${modelLanguage} (${matchSummary})`);+ }+ }+}++if (failures.length > 0) {+ console.error("Model language coverage check failed:\n");+ for (const failure of failures) console.error(` - ${failure}`);+ process.exit(1);+}++console.log(+ `Model language coverage: all catalog codes map to exactly one of ${MODEL_CAPABILITY_LANGUAGES.length} frontend intents`,+);diff --git a/src-tauri/src/managers/model.rs b/src-tauri/src/managers/model.rsindex bd75b5fa..4584b100 100644--- a/src-tauri/src/managers/model.rs+++ b/src-tauri/src/managers/model.rs@@ -90,15 +90,21 @@ fn recognition_language(language: &str) -> &str {}}-/// The base code Handy matches a language *intent* on: a tag's primary subtag,-/// with any BCP-47 region or script suffix dropped (`en-US` → `en`, `zh-CN` →-/// `zh`, `zh-Hant` → `zh`). Bare and three-letter codes (`haw`) pass through-/// unchanged. Lets a bare intent (`en`) match a model that advertises full-/// locales (`en-US`) without discarding the real code the engine needs.+/// A tag's primary language subtag, with any BCP-47 region/script suffix+/// dropped (`en-US` → `en`, `zh-Hant` → `zh`).fn base_language(language: &str) -> &str {- match language.split_once('-') {- Some((base, _)) => base,- None => language,+ language.split(&['-', '_'][..]).next().unwrap_or(language)+}++/// The stable user intent used to compare language codes across model+/// families. Norwegian Bokmål (`nb`) maps to Norwegian (`no`), while Nynorsk+/// (`nn`) remains distinct; Filipino (`fil`) maps to Tagalog (`tl`). This is+/// only for matching: callers must return/pass the model's original code.+pub(crate) fn canonical_language_code(language: &str) -> &str {+ match base_language(language) {+ "nb" => "no",+ "fil" => "tl",+ base => base,}}@@ -276,10 +282,19 @@ pub fn effective_language(}if intent != "auto" {- if let Some(code) = supported_languages+ // Prefer the same base code before considering an equivalence alias. If+ // a future model advertises both `no` and `nb`, an explicit `nb` intent+ // must select `nb`, regardless of capability-list order.+ let exact_base_match = supported_languages.iter()- .find(|language| base_language(language) == base_language(intent))- {+ .find(|language| base_language(language) == base_language(intent));+ let equivalent_match = || {+ supported_languages.iter().find(|language| {+ canonical_language_code(language) == canonical_language_code(intent)+ })+ };++ if let Some(code) = exact_base_match.or_else(equivalent_match) {if intent == "zh-Hans" || intent == "zh-Hant" {return intent.to_string();}@@ -2627,6 +2642,22 @@ mod tests {assert_eq!(effective_language("zh-Hant", &languages, true), "zh-Hant");}+ #[test]+ fn test_effective_language_preserves_intent_across_model_code_variants() {+ assert_eq!(effective_language("no", &["nb".to_string()], true), "nb");+ assert_eq!(effective_language("nb", &["no".to_string()], true), "no");+ assert_eq!(effective_language("tl", &["fil".to_string()], true), "fil");+ assert_eq!(effective_language("fil", &["tl".to_string()], true), "tl");+ }++ #[test]+ fn test_effective_language_prefers_exact_norwegian_code() {+ let languages = vec!["no".to_string(), "nb".to_string()];++ assert_eq!(effective_language("nb", &languages, true), "nb");+ assert_eq!(effective_language("no", &languages, true), "no");+ }+#[test]fn test_canonicalize_supported_languages_collapses_chinese_scripts() {let languages = canonicalize_supported_languages(diff --git a/src-tauri/src/managers/transcription.rs b/src-tauri/src/managers/transcription.rsindex 5ff5b8ce..4efbd0a9 100644--- a/src-tauri/src/managers/transcription.rs+++ b/src-tauri/src/managers/transcription.rs@@ -1646,10 +1646,6 @@ fn normalize_cjk_language(language: &str) -> &str {}}-fn base_language_code(language: &str) -> &str {- language.split(&['-', '_'][..]).next().unwrap_or(language)-}-/// Resolve the persisted language intent into the language a specific model can/// use without writing the coerced value back to settings.fn effective_language_for_model(@@ -1687,7 +1683,8 @@ fn resolve_output_language_evidence(if let Some(language) = applied_language_hint.filter(|lang| !lang.is_empty() && *lang != "auto"){if settings.selected_language != "auto"- && base_language_code(&settings.selected_language) == base_language_code(language)+ && crate::managers::model::canonical_language_code(&settings.selected_language)+ == crate::managers::model::canonical_language_code(language){return OutputLanguageEvidence::UserSelected(language.to_string());}@@ -2237,6 +2234,22 @@ mod tests {assert_eq!(result, "eu vi um carro");}+ #[test]+ fn norwegian_alias_is_recorded_as_user_selected_evidence() {+ let settings = AppSettings {+ selected_language: "no".to_string(),+ ..Default::default()+ };++ let evidence =+ resolve_output_language_evidence(&settings, Some("nb"), &languages(&["nb"]), false);++ assert_eq!(+ evidence,+ OutputLanguageEvidence::UserSelected("nb".to_string())+ );+ }+#[test]fn auto_language_without_detection_skips_gated_filler_removal() {let settings = AppSettings {diff --git a/src/components/settings/LanguageSelector.tsx b/src/components/settings/LanguageSelector.tsxindex b814c855..6385df9f 100644--- a/src/components/settings/LanguageSelector.tsx+++ b/src/components/settings/LanguageSelector.tsx@@ -19,23 +19,29 @@ interface LanguageSelectorProps {supportsLanguageDetection?: boolean;}+// Convert a concrete or aliased code to the picker entry that represents it.+// Chinese script intents are already selectable and must remain intact; model+// codes such as `en-US` and `nb` resolve to their canonical `en` / `no` entry.+const pickerLanguage = (languageCode: string): string =>+ SELECTABLE_LANGUAGES.some((language) => language.value === languageCode)+ ? languageCode+ : recognitionLanguage(languageCode);+// Mirrors the matching logic of `effective_language` in// src-tauri/src/managers/model.rs. The Rust function is authoritative for the-// *concrete* code the engine receives (e.g. "en-US"); this resolves the-// canonical *base* code ("en") so the highlighted picker item matches an entry-// in the LANGUAGES list. Matching is base-aware (`supportsLanguageCode` strips-// region/script subtags), so a model advertising full locales still resolves.+// *concrete* code the engine receives (e.g. `nb`); this resolves the canonical+// picker intent (e.g. `no`) so model switches preserve the user's language.const effectiveLanguage = (intent: string,supported: string[],supportsDetection: boolean,): string => {- if (supported.length === 0) return intent;+ if (supported.length === 0) return pickerLanguage(intent);if (intent !== "auto" && supportsLanguageCode(supported, intent))- return intent;+ return pickerLanguage(intent);if (supportsDetection) return "auto";if (supportsLanguageCode(supported, "en")) return "en";- return recognitionLanguage(supported[0]);+ return pickerLanguage(supported[0]);};export const LanguageSelector: React.FC<LanguageSelectorProps> = ({diff --git a/src/lib/constants/languages.ts b/src/lib/constants/languages.tsindex e250664a..44170b42 100644--- a/src/lib/constants/languages.ts+++ b/src/lib/constants/languages.ts@@ -5,6 +5,11 @@ export interface Language {export const CHINESE_LANGUAGE_CODE = "zh";+const LANGUAGE_ALIASES = new Map([+ ["nb", "no"],+ ["fil", "tl"],+]);+export const LANGUAGES: Language[] = [{ value: "auto", label: "Auto Detect" },{ value: "en", label: "English" },@@ -63,6 +68,7 @@ export const LANGUAGES: Language[] = [{ value: "br", label: "Breton" },{ value: "eu", label: "Basque" },{ value: "is", label: "Icelandic" },+ { value: "ga", label: "Irish" },{ value: "hy", label: "Armenian" },{ value: "ne", label: "Nepali" },{ value: "mn", label: "Mongolian" },@@ -99,7 +105,7 @@ export const LANGUAGES: Language[] = [{ value: "lb", label: "Luxembourgish" },{ value: "my", label: "Myanmar" },{ value: "bo", label: "Tibetan" },- { value: "tl", label: "Tagalog" },+ { value: "tl", label: "Filipino (Tagalog)" },{ value: "mg", label: "Malagasy" },{ value: "as", label: "Assamese" },{ value: "tt", label: "Tatar" },@@ -133,17 +139,21 @@ export const SELECTABLE_LANGUAGES: Language[] = LANGUAGES.filter((language) => language.value !== CHINESE_LANGUAGE_CODE,);-// Collapse a language tag to the base code Handy matches on, dropping any-// BCP-47 region or script subtag: "en-US" → "en", "zh-CN" → "zh", "zh-Hant" →-// "zh". Bare and three-letter codes ("haw") pass through unchanged. This lets-// the picker match a model's *real* codes — which may be full locales like-// "en-US" (e.g. Nemotron Streaming) — against Handy's canonical bare-code-// LANGUAGES list without the backend having to mangle the codes the engine needs.+// Collapse a language tag to the canonical recognition intent Handy exposes in+// the UI. BCP-47 region/script subtags are dropped ("en-US" → "en",+// "zh-Hant" → "zh"), and model-specific base-code equivalents are mapped to a+// stable intent. Norwegian Bokmål (`nb`) maps to Norwegian (`no`), while+// Nynorsk (`nn`) remains distinct; Filipino (`fil`) maps to Tagalog (`tl`). The+// backend performs the same equivalence match but returns the model's real code+// so the engine always receives exactly what it advertises.export const recognitionLanguage = (languageCode: string): string => {const separatorIndex = languageCode.indexOf("-");- return separatorIndex === -1- ? languageCode- : languageCode.slice(0, separatorIndex);+ const baseCode =+ separatorIndex === -1+ ? languageCode+ : languageCode.slice(0, separatorIndex);++ return LANGUAGE_ALIASES.get(baseCode) ?? baseCode;};export const supportsLanguageCode = (@@ -169,4 +179,5 @@ export const getUniqueCapabilityLanguages = (};export const getLanguageLabel = (languageCode: string): string | undefined =>- LANGUAGE_LABELS.get(languageCode);+ LANGUAGE_LABELS.get(languageCode) ??+ LANGUAGE_LABELS.get(recognitionLanguage(languageCode));