Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

feat: tag/folder Default Language is a localized dropdown fed by a shared ASR language module (also now backing the upload dialog's language options); legacy free-text codes round-trip as raw options

Murtaza Nasir9284a5e75dd5
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index e798f069..9c347c96 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -2814,54 +2814,13 @@ document.addEventListener('DOMContentLoaded', async () => {
];
});
- // Language options for ASR: the full Whisper language set (the
- // old hardcoded 11-language list locked out every other
- // supported language, issue #359). Labels come from
- // Intl.DisplayNames so they render localized without needing
- // translation keys for ~100 languages.
- const WHISPER_LANGUAGE_CODES = [
- 'en', 'zh', 'de', 'es', 'ru', 'ko', 'fr', 'ja', 'pt', 'tr', 'pl', 'ca',
- 'nl', 'ar', 'sv', 'it', 'id', 'hi', 'fi', 'vi', 'he', 'uk', 'el', 'ms',
- 'cs', 'ro', 'da', 'hu', 'ta', 'no', 'th', 'ur', 'hr', 'bg', 'lt', 'la',
- 'mi', 'ml', 'cy', 'sk', 'te', 'fa', 'lv', 'bn', 'sr', 'az', 'sl', 'kn',
- 'et', 'mk', 'br', 'eu', 'is', 'hy', 'ne', 'mn', 'bs', 'kk', 'sq', 'sw',
- 'gl', 'mr', 'pa', 'si', 'km', 'sn', 'yo', 'so', 'af', 'oc', 'ka', 'be',
- 'tg', 'sd', 'gu', 'am', 'yi', 'lo', 'uz', 'fo', 'ht', 'ps', 'tk', 'nn',
- 'mt', 'sa', 'lb', 'my', 'bo', 'tl', 'mg', 'as', 'tt', 'haw', 'ln', 'ha',
- 'ba', 'jw', 'su', 'yue'
- ];
- // Codes Intl.DisplayNames can't resolve (or resolves under a
- // different ISO tag than Whisper uses).
- const WHISPER_LANGUAGE_LABEL_OVERRIDES = {
- jw: 'jv', // Whisper uses 'jw' for Javanese (ISO is 'jv')
- };
- const WHISPER_LANGUAGE_FALLBACK_NAMES = {
- haw: 'Hawaiian',
- yue: 'Cantonese',
- ba: 'Bashkir', // some ICU builds return the bare code
- bo: 'Tibetan',
- };
+ // Language options for ASR: the full Whisper language set with
+ // localized labels, from the shared asr-languages.js module
+ // (also feeds the tag/folder modals' Default Language selects).
const languageOptions = computed(() => {
- const uiLocale = (window.i18n && window.i18n.currentLocale) || 'en';
- let displayNames = null;
- try {
- displayNames = new Intl.DisplayNames([uiLocale, 'en'], { type: 'language' });
- } catch (e) { /* very old browsers: fall back to raw codes */ }
- const options = WHISPER_LANGUAGE_CODES.map(code => {
- const lookup = WHISPER_LANGUAGE_LABEL_OVERRIDES[code] || code;
- let label = null;
- if (displayNames) {
- try {
- const name = displayNames.of(lookup);
- // DisplayNames echoes back unknown codes; treat that as a miss
- if (name && name !== lookup) label = name;
- } catch (e) { /* invalid tag for this engine */ }
- }
- if (!label) label = WHISPER_LANGUAGE_FALLBACK_NAMES[code] || code;
- label = label.charAt(0).toLocaleUpperCase(uiLocale) + label.slice(1);
- return { value: code, label };
- });
- options.sort((a, b) => a.label.localeCompare(b.label, uiLocale));
+ const options = window.SpeakrASRLanguages
+ ? window.SpeakrASRLanguages.buildOptions((window.i18n && window.i18n.currentLocale) || 'en')
+ : [];
return [{ value: '', label: t('form.autoDetect') }, ...options];
});
diff --git a/static/js/asr-languages.js b/static/js/asr-languages.js
new file mode 100644
index 00000000..8351ac8b
--- /dev/null
+++ b/static/js/asr-languages.js
@@ -0,0 +1,107 @@
+/**
+ * Shared ASR language list + localized dropdown options.
+ *
+ * Single source of truth for the Whisper language set, used by:
+ * - the Vue app's transcription-language dropdowns (app.modular.js
+ * `languageOptions`), and
+ * - the tag/folder editor modals' Default Language selects
+ * (organizer-modals.js), on both the account page and the main app.
+ *
+ * Labels come from Intl.DisplayNames so ~100 languages render localized
+ * without translation keys; values stay the short codes the ASR backend
+ * expects (en, es, zh, ...).
+ */
+(function () {
+ 'use strict';
+
+ // The full Whisper language set (the old hardcoded 11-language list
+ // locked out every other supported language, issue #359).
+ const CODES = [
+ 'en', 'zh', 'de', 'es', 'ru', 'ko', 'fr', 'ja', 'pt', 'tr', 'pl', 'ca',
+ 'nl', 'ar', 'sv', 'it', 'id', 'hi', 'fi', 'vi', 'he', 'uk', 'el', 'ms',
+ 'cs', 'ro', 'da', 'hu', 'ta', 'no', 'th', 'ur', 'hr', 'bg', 'lt', 'la',
+ 'mi', 'ml', 'cy', 'sk', 'te', 'fa', 'lv', 'bn', 'sr', 'az', 'sl', 'kn',
+ 'et', 'mk', 'br', 'eu', 'is', 'hy', 'ne', 'mn', 'bs', 'kk', 'sq', 'sw',
+ 'gl', 'mr', 'pa', 'si', 'km', 'sn', 'yo', 'so', 'af', 'oc', 'ka', 'be',
+ 'tg', 'sd', 'gu', 'am', 'yi', 'lo', 'uz', 'fo', 'ht', 'ps', 'tk', 'nn',
+ 'mt', 'sa', 'lb', 'my', 'bo', 'tl', 'mg', 'as', 'tt', 'haw', 'ln', 'ha',
+ 'ba', 'jw', 'su', 'yue'
+ ];
+ // Codes Intl.DisplayNames can't resolve (or resolves under a different
+ // ISO tag than Whisper uses).
+ const LABEL_OVERRIDES = {
+ jw: 'jv', // Whisper uses 'jw' for Javanese (ISO is 'jv')
+ };
+ const FALLBACK_NAMES = {
+ haw: 'Hawaiian',
+ yue: 'Cantonese',
+ ba: 'Bashkir', // some ICU builds return the bare code
+ bo: 'Tibetan',
+ };
+
+ /** Localized {value, label} options, sorted by label. No empty entry. */
+ function buildOptions(locale) {
+ const uiLocale = locale || (window.i18n && window.i18n.currentLocale) || 'en';
+ let displayNames = null;
+ try {
+ displayNames = new Intl.DisplayNames([uiLocale, 'en'], { type: 'language' });
+ } catch (e) { /* very old browsers: fall back to raw codes */ }
+ const options = CODES.map(code => {
+ const lookup = LABEL_OVERRIDES[code] || code;
+ let label = null;
+ if (displayNames) {
+ try {
+ const name = displayNames.of(lookup);
+ // DisplayNames echoes back unknown codes; treat that as a miss
+ if (name && name !== lookup) label = name;
+ } catch (e) { /* invalid tag for this engine */ }
+ }
+ if (!label) label = FALLBACK_NAMES[code] || code;
+ label = label.charAt(0).toLocaleUpperCase(uiLocale) + label.slice(1);
+ return { value: code, label };
+ });
+ options.sort((a, b) => a.label.localeCompare(b.label, uiLocale));
+ return options;
+ }
+
+ /**
+ * Fill a <select> with the language options, preserving its current
+ * value across repopulation (locale changes). The first entry is an
+ * empty-value option labeled emptyLabel.
+ */
+ function populateSelect(select, emptyLabel) {
+ if (!select) return;
+ const previous = select.value;
+ select.textContent = '';
+ const emptyOpt = document.createElement('option');
+ emptyOpt.value = '';
+ emptyOpt.textContent = emptyLabel || 'Auto detect';
+ select.appendChild(emptyOpt);
+ for (const { value, label } of buildOptions()) {
+ const opt = document.createElement('option');
+ opt.value = value;
+ opt.textContent = label + ' (' + value + ')';
+ select.appendChild(opt);
+ }
+ if (previous) setValue(select, previous);
+ }
+
+ /**
+ * Select a stored code, appending it as a raw option if it isn't in the
+ * list (legacy free-text values keep round-tripping instead of being
+ * silently dropped on the next save).
+ */
+ function setValue(select, value) {
+ if (!select) return;
+ value = value || '';
+ if (value && ![...select.options].some(o => o.value === value)) {
+ const opt = document.createElement('option');
+ opt.value = value;
+ opt.textContent = value;
+ select.appendChild(opt);
+ }
+ select.value = value;
+ }
+
+ window.SpeakrASRLanguages = { CODES, buildOptions, populateSelect, setValue };
+})();
diff --git a/static/js/organizer-modals.js b/static/js/organizer-modals.js
index a81e9b3e..a0dabb60 100644
--- a/static/js/organizer-modals.js
+++ b/static/js/organizer-modals.js
@@ -213,6 +213,9 @@
if (translated && translated !== key) el.placeholder = translated;
});
}
+ // Relocalize the language dropdowns now that i18n is ready (the
+ // initial DOMContentLoaded population can predate i18n.init).
+ populateLanguageSelects();
// Modal tab strips (the account page binds its own copies of these).
document.getElementById('tagModalTabs')?.addEventListener('click', (e) => {
@@ -376,12 +379,48 @@
setTimeout(() => document.getElementById('folderName')?.focus(), 50);
}
+ // ------------------------------------------------------------------
+ // Default Language selects: localized dropdown instead of free-text
+ // codes, fed from the shared list (asr-languages.js) on both pages.
+ // ------------------------------------------------------------------
+
+ function populateLanguageSelects() {
+ if (!window.SpeakrASRLanguages) return;
+ const emptyLabel = tr('form.autoDetect', 'Auto detect');
+ window.SpeakrASRLanguages.populateSelect(document.getElementById('tagLanguage'), emptyLabel);
+ window.SpeakrASRLanguages.populateSelect(document.getElementById('folderLanguage'), emptyLabel);
+ }
+
+ /** Select a stored language code, keeping unknown legacy codes intact. */
+ function setLanguageValue(selectId, value) {
+ const select = document.getElementById(selectId);
+ if (!select) return;
+ if (window.SpeakrASRLanguages) {
+ if (!select.options.length) populateLanguageSelects();
+ window.SpeakrASRLanguages.setValue(select, value);
+ } else {
+ select.value = value || '';
+ }
+ }
+
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', populateLanguageSelects);
+ } else {
+ populateLanguageSelects();
+ }
+ // Repopulate with relocalized labels once i18n resolves the locale
+ // (initial population can run before i18n.init finishes). Values are
+ // preserved across repopulation.
+ window.addEventListener('localeChanged', populateLanguageSelects);
+
window.SpeakrOrganizer = {
loadTemplateOptionsInto,
buildTagPayload,
buildFolderPayload,
openTagCreate,
openFolderCreate,
+ setLanguageValue,
+ populateLanguageSelects,
};
// The account page's inline script calls this by its bare name.
window.loadTemplateOptionsInto = loadTemplateOptionsInto;
diff --git a/templates/account.html b/templates/account.html
index c226b166..3df0cd80 100644
--- a/templates/account.html
+++ b/templates/account.html
@@ -14,6 +14,7 @@
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/primitives.css') }}">
<script src="{{ url_for('static', filename='js/i18n.js') }}"></script>
+ <script src="{{ url_for('static', filename='js/asr-languages.js') }}"></script>
<script src="{{ url_for('static', filename='js/organizer-modals.js') }}"></script>
<!-- Loading overlay to prevent FOUC -->
@@ -121,6 +122,10 @@
// current locale's alphabetical order. Values stay intact so
// already-saved user preferences continue to resolve.
sortLanguageDropdowns();
+
+ // Relocalize the tag/folder modals' language dropdowns too
+ // (their initial population can predate i18n.init).
+ window.SpeakrOrganizer?.populateLanguageSelects?.();
}
}
@@ -5043,9 +5048,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
}
// Populate ASR settings
- if (document.getElementById('tagLanguage')) {
- document.getElementById('tagLanguage').value = tag.default_language || '';
- }
+ window.SpeakrOrganizer.setLanguageValue('tagLanguage', tag.default_language);
if (document.getElementById('tagMinSpeakers')) {
document.getElementById('tagMinSpeakers').value = tag.default_min_speakers || '';
}
@@ -5519,8 +5522,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
document.getElementById('folderName').value = folder.name;
document.getElementById('folderColor').value = folder.color;
document.getElementById('folderCustomPrompt').value = folder.custom_prompt || '';
- var langField = document.getElementById('folderLanguage');
- if (langField) langField.value = folder.default_language || '';
+ window.SpeakrOrganizer.setLanguageValue('folderLanguage', folder.default_language);
var minField = document.getElementById('folderMinSpeakers');
if (minField) minField.value = folder.default_min_speakers || '';
var maxField = document.getElementById('folderMaxSpeakers');
diff --git a/templates/includes/organizer_modals.html b/templates/includes/organizer_modals.html
index 761d1ab7..596e97ad 100644
--- a/templates/includes/organizer_modals.html
+++ b/templates/includes/organizer_modals.html
@@ -77,7 +77,7 @@
<div class="space-y-3">
<div>
<label for="tagLanguage" class="block text-sm font-medium text-[var(--text-muted)] mb-1" data-i18n="editTagModal.defaultLanguage">Default Language</label>
- <input type="text" id="tagLanguage" name="default_language" maxlength="10" class="w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md focus:outline-none focus:ring-2 focus:ring-[var(--border-focus)] bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="e.g., en, es, zh">
+ <select id="tagLanguage" name="default_language" class="w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md focus:outline-none focus:ring-2 focus:ring-[var(--border-focus)] bg-[var(--bg-input)] text-[var(--text-primary)]"></select>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
@@ -299,7 +299,7 @@
<div class="space-y-3">
<div>
<label for="folderLanguage" class="block text-sm font-medium text-[var(--text-muted)] mb-1" data-i18n="folderManagement.defaultLanguage">Default Language</label>
- <input type="text" id="folderLanguage" name="default_language" maxlength="10" class="w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md focus:outline-none focus:ring-2 focus:ring-[var(--border-focus)] bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="e.g., en, es, zh">
+ <select id="folderLanguage" name="default_language" class="w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md focus:outline-none focus:ring-2 focus:ring-[var(--border-focus)] bg-[var(--bg-input)] text-[var(--text-primary)]"></select>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
diff --git a/templates/index.html b/templates/index.html
index eba051d5..bcc6601c 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -228,6 +228,9 @@
<!-- Service Worker Registration handled by app.modular.js -->
+ <!-- Shared ASR language list (feeds Vue dropdowns and the organizer modals) -->
+ <script src="{{ url_for('static', filename='js/asr-languages.js') }}"></script>
+
<!-- Shared tag/folder modal driver (standalone creation mode) -->
<script src="{{ url_for('static', filename='js/organizer-modals.js') }}"></script>