Skip to content

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

Python

Format dates, times and numbers in the interface language (#480)

Murtaza Nasir2f4893778c0f
diff --git a/docs/user-guide/settings.md b/docs/user-guide/settings.md
index fc3c703e..06cbaf0d 100644
--- a/docs/user-guide/settings.md
+++ b/docs/user-guide/settings.md
@@ -129,7 +129,7 @@ The Preferences tab is the home for display and editor behaviour settings that s
Three language settings shape your Speakr experience. The interface language dropdown immediately transforms all menus, buttons, and messages to your chosen language; the transcription language field sets a default ISO 639-1 code that the recognition service uses to optimise accuracy when auto-detect is too slow or ambiguous; and the preferred output language controls the language of titles, summaries, and chat responses regardless of the source audio's language. Leaving the transcription language on **Auto-detect** is the right default for multilingual content.
-The interface language also applies to the notices shown after account actions, such as signing in, saving settings or changing a password, and to the email verification and password reset messages. Error messages returned by the API are still in English. Text without a translation for the selected language is shown in English.
+The interface language also applies to the notices shown after account actions, such as signing in, saving settings or changing a password, and to the email verification and password reset messages. Error messages returned by the API are still in English. Text without a translation for the selected language is shown in English. Dates, times and numbers are formatted for the interface language, independent of the browser language: month and weekday names, the decimal separator and the 12- or 24-hour clock all follow the selected language.
These settings used to live on the Account Information tab. They moved here so all preferences that affect your day-to-day Speakr experience live in one place.
diff --git a/static/js/account-webhooks.js b/static/js/account-webhooks.js
index 57d11374..00db644b 100644
--- a/static/js/account-webhooks.js
+++ b/static/js/account-webhooks.js
@@ -67,7 +67,7 @@
function fmt(dt) {
if (!dt) return '—';
- try { return parseServerInstant(dt).toLocaleString(); } catch (_) { return String(dt); }
+ try { return parseServerInstant(dt).toLocaleString(window.i18n?.getIntlLocale()); } catch (_) { return String(dt); }
}
function statusBadge(wh) {
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 3706806a..1979338e 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -2061,7 +2061,7 @@ document.addEventListener('DOMContentLoaded', async () => {
if (isNaN(date.getTime())) {
return dateString;
}
- return date.toLocaleDateString(undefined, {
+ return date.toLocaleDateString(window.i18n?.getIntlLocale(), {
year: 'numeric', month: 'short', day: 'numeric',
hour: '2-digit', minute: '2-digit'
});
@@ -2086,9 +2086,9 @@ document.addEventListener('DOMContentLoaded', async () => {
const now = new Date();
const isCurrentYear = date.getFullYear() === now.getFullYear();
if (isCurrentYear) {
- return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
+ return date.toLocaleDateString(window.i18n?.getIntlLocale(), { month: 'short', day: 'numeric' });
}
- return date.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
+ return date.toLocaleDateString(window.i18n?.getIntlLocale(), { year: 'numeric', month: 'short', day: 'numeric' });
} catch (e) {
return dateString;
}
@@ -2151,9 +2151,9 @@ document.addEventListener('DOMContentLoaded', async () => {
if (!dateString) return '';
const date = new Date(dateString);
if (timeOnly) {
- return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
+ return date.toLocaleTimeString(window.i18n?.getIntlLocale(), { hour: '2-digit', minute: '2-digit' });
}
- return date.toLocaleString([], {
+ return date.toLocaleString(window.i18n?.getIntlLocale(), {
weekday: 'short', month: 'short', day: 'numeric',
hour: '2-digit', minute: '2-digit'
});
@@ -4486,6 +4486,8 @@ document.addEventListener('DOMContentLoaded', async () => {
// Utilities
formatFileSize,
+ // The interface locale for toLocale*String calls in templates (#480)
+ uiLocale: () => window.i18n?.getIntlLocale(),
parseServerInstant,
formatDisplayDate,
formatShortDate,
diff --git a/static/js/global-header.js b/static/js/global-header.js
index 4b271c22..be2e1e6e 100644
--- a/static/js/global-header.js
+++ b/static/js/global-header.js
@@ -89,6 +89,8 @@ async function mountGlobalHeader() {
return {
t,
+ // components/header-controls.html formats numbers with this (#480)
+ uiLocale: () => window.i18n?.getIntlLocale(),
...notifications,
isUserMenuOpen,
tokenBudget,
diff --git a/static/js/i18n.js b/static/js/i18n.js
index 876283e4..e18c1d07 100644
--- a/static/js/i18n.js
+++ b/static/js/i18n.js
@@ -135,6 +135,21 @@ class I18n {
return this.currentLocale;
}
+ /**
+ * The interface locale as a language tag for Intl and the toLocale*String
+ * methods, so dates and numbers follow the selected language (#480).
+ * Undefined, which Intl reads as the browser default, when the stored code
+ * is not a valid tag: Intl throws on one, and a date should still render.
+ * @returns {string|undefined}
+ */
+ getIntlLocale() {
+ try {
+ return Intl.getCanonicalLocales(this.currentLocale)[0];
+ } catch (e) {
+ return undefined;
+ }
+ }
+
/**
* Get available locales
* @returns {Array} List of available locale codes
@@ -240,7 +255,7 @@ class I18n {
*/
formatDate(date, options = {}) {
const d = date instanceof Date ? date : new Date(date);
- return new Intl.DateTimeFormat(this.currentLocale, options).format(d);
+ return new Intl.DateTimeFormat(this.getIntlLocale(), options).format(d);
}
/**
@@ -250,7 +265,7 @@ class I18n {
* @returns {string} Formatted number string
*/
formatNumber(number, options = {}) {
- return new Intl.NumberFormat(this.currentLocale, options).format(number);
+ return new Intl.NumberFormat(this.getIntlLocale(), options).format(number);
}
/**
diff --git a/static/js/i18n.test.js b/static/js/i18n.test.js
index 48172037..22693e1e 100644
--- a/static/js/i18n.test.js
+++ b/static/js/i18n.test.js
@@ -108,3 +108,39 @@ describe('i18n bootstrap', () => {
expect(events.map(e => e.type)).toEqual(['i18nReady', 'localeChanged']);
});
});
+
+describe('interface locale for dates and numbers (#480)', () => {
+ const at = new Date(Date.UTC(2026, 9, 17, 14, 30));
+
+ it('returns the selected language as an Intl tag', () => {
+ for (const code of ['en', 'de', 'es', 'fr', 'ru', 'zh', 'pt-BR']) {
+ const { i18n } = load({ bootstrap: { locale: code, translations: { [code]: {}, en: EN } } });
+ expect(i18n.getIntlLocale()).toBe(code);
+ expect(() => new Intl.DateTimeFormat(i18n.getIntlLocale())).not.toThrow();
+ }
+ });
+
+ it('falls back to the browser default for a code Intl rejects', () => {
+ const { i18n } = load({ bootstrap: { locale: 'en', translations: { en: EN } }, saved: 'not a tag!' });
+ expect(i18n.getLocale()).toBe('not a tag!');
+ expect(i18n.getIntlLocale()).toBeUndefined();
+ expect(() => i18n.formatDate(at, { timeZone: 'UTC' })).not.toThrow();
+ expect(() => i18n.formatNumber(1.5)).not.toThrow();
+ });
+
+ it('formats dates and numbers in the interface language, not the browser one', () => {
+ const { i18n } = load({ bootstrap: { locale: 'de', translations: { de: DE, en: EN } } });
+ const opts = { month: 'short', day: 'numeric', timeZone: 'UTC' };
+ expect(i18n.formatDate(at, opts)).toBe('17. Okt.');
+ expect(at.toLocaleDateString(i18n.getIntlLocale(), opts)).toBe('17. Okt.');
+ expect(at.toLocaleTimeString(i18n.getIntlLocale(), { hour: 'numeric', minute: '2-digit', timeZone: 'UTC' })).toBe('14:30');
+ expect(i18n.formatNumber(1234.5)).toBe('1.234,5');
+ });
+
+ it('keeps the English formats for English', () => {
+ const { i18n } = load({ bootstrap: { locale: 'en', translations: { en: EN } } });
+ expect(i18n.formatDate(at, { month: 'short', day: 'numeric', timeZone: 'UTC' })).toBe('Oct 17');
+ expect(at.toLocaleTimeString(i18n.getIntlLocale(), { hour: 'numeric', minute: '2-digit', timeZone: 'UTC' })).toMatch(/^2:30\sPM$/); // ICU may use a narrow no-break space
+ expect(i18n.formatNumber(1234.5)).toBe('1,234.5');
+ });
+});
diff --git a/static/js/modules/composables/sharing.js b/static/js/modules/composables/sharing.js
index 59abb04c..9626e4ad 100644
--- a/static/js/modules/composables/sharing.js
+++ b/static/js/modules/composables/sharing.js
@@ -49,21 +49,25 @@ export function useSharing(state, utils) {
const diffMs = now - date;
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
+ // The interface locale picks the words and the 12/24-hour clock (#480).
+ const locale = window.i18n?.getIntlLocale();
+ const time = () => date.toLocaleTimeString(locale, { hour: 'numeric', minute: '2-digit' });
+
// If today
if (diffDays === 0) {
- return 'Today at ' + date.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', hour12: true });
+ return (utils.t ? utils.t('sidebar.today') : 'Today') + ', ' + time();
}
// If yesterday
else if (diffDays === 1) {
- return 'Yesterday at ' + date.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', hour12: true });
+ return (utils.t ? utils.t('sidebar.yesterday') : 'Yesterday') + ', ' + time();
}
// If within last week
else if (diffDays < 7) {
- return date.toLocaleDateString('en-US', { weekday: 'long', hour: 'numeric', minute: '2-digit', hour12: true });
+ return date.toLocaleDateString(locale, { weekday: 'long', hour: 'numeric', minute: '2-digit' });
}
// Otherwise show full date
else {
- return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit', hour12: true });
+ return date.toLocaleDateString(locale, { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit' });
}
} catch (e) {
console.error('Error formatting date:', e);
diff --git a/static/js/modules/composables/tokens.js b/static/js/modules/composables/tokens.js
index ac424054..e51b8955 100644
--- a/static/js/modules/composables/tokens.js
+++ b/static/js/modules/composables/tokens.js
@@ -49,7 +49,7 @@ export function useTokens({ showToast, setGlobalError }) {
const formatTokenDate = (dateString) => {
if (!dateString) return 'Never';
const date = parseServerInstant(dateString);
- return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
+ return date.toLocaleDateString(window.i18n?.getIntlLocale()) + ' ' + date.toLocaleTimeString(window.i18n?.getIntlLocale());
};
const getTokenStatus = (token) => {
diff --git a/static/js/modules/composables/ui.js b/static/js/modules/composables/ui.js
index 8f537c1d..34a1f1b0 100644
--- a/static/js/modules/composables/ui.js
+++ b/static/js/modules/composables/ui.js
@@ -909,7 +909,7 @@ export function useUI(state, utils, processedTranscription) {
hour: '2-digit',
minute: '2-digit'
};
- return date.toLocaleString(undefined, options);
+ return date.toLocaleString(window.i18n?.getIntlLocale(), options);
} catch (e) {
return dateTimeStr;
}
diff --git a/static/js/modules/composables/upload.js b/static/js/modules/composables/upload.js
index 7ff82f4c..42d50bd3 100644
--- a/static/js/modules/composables/upload.js
+++ b/static/js/modules/composables/upload.js
@@ -897,7 +897,7 @@ export function useUpload(state, utils) {
if (data.duplicate_warning) {
const warning = data.duplicate_warning;
const existingDate = warning.existing_created_at
- ? utils.parseServerInstant(warning.existing_created_at).toLocaleDateString()
+ ? utils.parseServerInstant(warning.existing_created_at).toLocaleDateString(window.i18n?.getIntlLocale())
: '';
const existingName = warning.existing_title || 'Unknown';
showToast(
diff --git a/templates/account.html b/templates/account.html
index bbdff017..4925198c 100644
--- a/templates/account.html
+++ b/templates/account.html
@@ -3252,8 +3252,8 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
const activeFilter = searchInput ? searchInput.value : '';
speakersTabData.forEach(speaker => {
- const createdDate = parseInstant(speaker.created_at).toLocaleDateString();
- const lastUsedDate = parseInstant(speaker.last_used).toLocaleDateString();
+ const createdDate = parseInstant(speaker.created_at).toLocaleDateString(window.i18n?.getIntlLocale());
+ const lastUsedDate = parseInstant(speaker.last_used).toLocaleDateString(window.i18n?.getIntlLocale());
// Voice profile status
const hasVoiceProfile = speaker.embedding_count && speaker.embedding_count > 0;
@@ -4354,7 +4354,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
if (!dateString) return '';
const d = parseInstant(dateString);
if (isNaN(d.getTime())) return dateString;
- return d.toLocaleString();
+ return d.toLocaleString(window.i18n?.getIntlLocale());
}
// ---- AJAX form submission for the settings forms --------
@@ -4606,8 +4606,8 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
const div = document.createElement('div');
div.className = 'flex items-center justify-between p-3 bg-[var(--bg-tertiary)] rounded-lg border border-[var(--border-primary)] hover:bg-[var(--bg-accent)] transition-colors duration-200';
- const createdDate = parseInstant(speaker.created_at).toLocaleDateString();
- const lastUsedDate = parseInstant(speaker.last_used).toLocaleDateString();
+ const createdDate = parseInstant(speaker.created_at).toLocaleDateString(window.i18n?.getIntlLocale());
+ const lastUsedDate = parseInstant(speaker.last_used).toLocaleDateString(window.i18n?.getIntlLocale());
div.innerHTML = `
<div class="flex-1">
@@ -6274,8 +6274,8 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
activeTokensList.innerHTML = activeTokens.map(token => {
const statusClass = getTokenStatusClass(token);
const status = getTokenStatus(token);
- const createdDate = parseInstant(token.created_at).toLocaleDateString();
- const lastUsed = token.last_used_at ? parseInstant(token.last_used_at).toLocaleDateString() : null;
+ const createdDate = parseInstant(token.created_at).toLocaleDateString(window.i18n?.getIntlLocale());
+ const lastUsed = token.last_used_at ? parseInstant(token.last_used_at).toLocaleDateString(window.i18n?.getIntlLocale()) : null;
return `
<div class="bg-[var(--bg-tertiary)] rounded-lg border border-[var(--border-primary)] hover:border-[var(--border-accent)] transition-colors duration-200">
@@ -6319,7 +6319,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
${token.expires_at ? `
<span class="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium bg-blue-100 text-blue-800">
<i class="fas fa-hourglass-half"></i>
- Expires ${parseInstant(token.expires_at).toLocaleDateString()}
+ Expires ${parseInstant(token.expires_at).toLocaleDateString(window.i18n?.getIntlLocale())}
</span>
` : `
<span class="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium bg-gray-100 text-gray-600">
@@ -6352,7 +6352,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
s = s.replace(' ', 'T') + 'Z';
}
const date = new Date(s);
- return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
+ return date.toLocaleDateString(window.i18n?.getIntlLocale()) + ' ' + date.toLocaleTimeString(window.i18n?.getIntlLocale());
}
function getTokenStatus(token) {
diff --git a/templates/admin.html b/templates/admin.html
index f9063d8f..897da596 100644
--- a/templates/admin.html
+++ b/templates/admin.html
@@ -345,7 +345,7 @@
<div class="mt-3 grid grid-cols-2 sm:grid-cols-3 gap-3 text-sm">
<div>
<p class="text-xs text-[var(--text-muted)]">${t('adminDashboard.statsPage.created')}</p>
- <p class="font-semibold text-[var(--text-primary)]" v-text="overview ? overview.activity.created.toLocaleString() : '—'"></p>
+ <p class="font-semibold text-[var(--text-primary)]" v-text="overview ? overview.activity.created.toLocaleString(uiLocale()) : '—'"></p>
</div>
<div>
<p class="text-xs text-[var(--text-muted)]">${t('adminDashboard.statsPage.medianProcessing')}</p>
@@ -369,7 +369,7 @@
<dt class="flex items-center gap-1.5 text-[var(--text-secondary)] truncate">
<span class="inline-block w-2 h-2 rounded-full flex-shrink-0" :style="{ background: s.color }"></span><span v-text="s.label"></span>
</dt>
- <dd class="font-semibold text-[var(--text-primary)]" v-text="(s.value || 0).toLocaleString()"></dd>
+ <dd class="font-semibold text-[var(--text-primary)]" v-text="(s.value || 0).toLocaleString(uiLocale())"></dd>
</div>
</template>
</dl>
@@ -493,9 +493,9 @@
<span class="block truncate max-w-[16rem] text-[var(--text-primary)]" :title="m.model" v-text="m.model || '—'"></span>
<span class="text-xs text-[var(--text-muted)]" v-text="t('adminDashboard.statsPage.kind.' + m.kind)"></span>
</td>
- <td class="py-1.5 pr-3 text-right tabular-nums" v-text="m.requests.toLocaleString()"></td>
+ <td class="py-1.5 pr-3 text-right tabular-nums" v-text="m.requests.toLocaleString(uiLocale())"></td>
<td class="py-1.5 pr-3 text-right tabular-nums whitespace-nowrap"
- v-text="m.kind === 'transcription' ? t('adminDashboard.statsPage.minutesShort', { count: Math.round(m.minutes).toLocaleString() }) : formatCompact(m.tokens)"></td>
+ v-text="m.kind === 'transcription' ? t('adminDashboard.statsPage.minutesShort', { count: Math.round(m.minutes).toLocaleString(uiLocale()) }) : formatCompact(m.tokens)"></td>
<td class="py-1.5 text-right tabular-nums whitespace-nowrap" v-text="formatModelCost(m)"></td>
</tr>
</tbody>
@@ -529,7 +529,7 @@
:class="(u.token_pct || 0) >= 100 || (u.minutes_pct || 0) >= 100 || (u.storage_pct || 0) >= 100 ? 'text-[var(--text-danger-strong)]' : 'text-[var(--text-warn-strong)]'"
:title="t('adminDashboard.statsPage.nearBudget')"></i>
</td>
- <td class="py-2 px-3 text-right tabular-nums" v-text="u.recordings.toLocaleString()"></td>
+ <td class="py-2 px-3 text-right tabular-nums" v-text="u.recordings.toLocaleString(uiLocale())"></td>
<td class="py-2 px-3 text-right min-w-[7rem]">
<span class="tabular-nums whitespace-nowrap" v-text="formatFileSize(u.storage)"></span><span v-if="u.storage_quota" class="text-xs text-[var(--text-muted)] whitespace-nowrap"> / <span v-text="formatFileSize(u.storage_quota)"></span></span>
<div v-if="u.storage_quota" class="w-full bg-[var(--bg-secondary)] rounded-full h-1 mt-1">
@@ -544,7 +544,7 @@
</div>
</td>
<td class="py-2 px-3 text-right min-w-[8rem]">
- <span class="tabular-nums" v-text="u.minutes_month.toLocaleString()"></span><span v-if="u.minutes_budget" class="text-xs text-[var(--text-muted)]"> / <span v-text="u.minutes_budget.toLocaleString()"></span></span>
+ <span class="tabular-nums" v-text="u.minutes_month.toLocaleString(uiLocale())"></span><span v-if="u.minutes_budget" class="text-xs text-[var(--text-muted)]"> / <span v-text="u.minutes_budget.toLocaleString(uiLocale())"></span></span>
<div v-if="u.minutes_budget" class="w-full bg-[var(--bg-secondary)] rounded-full h-1 mt-1">
<div class="h-1 rounded-full" :class="budgetBarClass(u.minutes_pct)" :style="{ width: Math.min(u.minutes_pct || 0, 100) + '%' }"></div>
</div>
@@ -687,13 +687,13 @@
<i class="fas fa-infinity mr-1"></i> ${t('adminDashboard.noLimit')}
</span>
<span v-else-if="setting.key === 'transcript_length_limit'" class="text-[var(--text-primary)]">
- ${ Number(setting.value).toLocaleString() } ${t('adminDashboard.characters')}
+ ${ Number(setting.value).toLocaleString(uiLocale()) } ${t('adminDashboard.characters')}
</span>
<span v-else-if="setting.key === 'max_file_size_mb'" class="text-[var(--text-primary)]">
- ${ Number(setting.value).toLocaleString() } ${t('adminDashboard.megabytes')}
+ ${ Number(setting.value).toLocaleString(uiLocale()) } ${t('adminDashboard.megabytes')}
</span>
<span v-else-if="setting.key === 'asr_timeout_seconds'" class="text-[var(--text-primary)]">
- ${ Number(setting.value).toLocaleString() } ${t('adminDashboard.seconds')}
+ ${ Number(setting.value).toLocaleString(uiLocale()) } ${t('adminDashboard.seconds')}
</span>
<span v-else-if="setting.value && setting.value.length > 80" class="text-[var(--text-muted)] italic">${ setting.value.substring(0, 80) }...</span>
<span v-else>${ setting.value || t('adminDashboard.notSet') }</span>
@@ -1170,7 +1170,7 @@ Summarization Instructions:
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-[var(--text-muted)]">Embedding API tokens</p>
- <p class="text-2xl font-semibold text-[var(--text-primary)]">${ (inquireStatus.embedding_usage && inquireStatus.embedding_usage.total_tokens || 0).toLocaleString() }</p>
+ <p class="text-2xl font-semibold text-[var(--text-primary)]">${ (inquireStatus.embedding_usage && inquireStatus.embedding_usage.total_tokens || 0).toLocaleString(uiLocale()) }</p>
<p class="text-xs text-[var(--text-muted)] mt-1">${ inquireStatus.embedding_usage && inquireStatus.embedding_usage.request_count || 0 } API requests</p>
</div>
<i class="fas fa-coins text-3xl text-[var(--text-accent)] opacity-50"></i>
@@ -1291,7 +1291,7 @@ Summarization Instructions:
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-[var(--text-muted)]">
- ${ parseInstant(group.created_at).toLocaleDateString() }
+ ${ parseInstant(group.created_at).toLocaleDateString(uiLocale()) }
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium space-x-2">
<button @click="openManageTeamModal(group)" class="text-[var(--text-accent)] hover:opacity-80" title="Manage Members">
@@ -1423,7 +1423,7 @@ Summarization Instructions:
<p class="text-xs text-[var(--text-muted)] mt-1">${t('adminDashboard.tokenBudgetHelp')}</p>
<div v-if="editingUser.monthly_token_budget && editingUser.current_token_usage !== undefined" class="mt-2">
<div class="flex justify-between text-xs text-[var(--text-muted)] mb-1">
- <span>${t('adminDashboard.currentUsage')}: ${ editingUser.current_token_usage?.toLocaleString() || 0 } ${t('adminDashboard.tokens')}</span>
+ <span>${t('adminDashboard.currentUsage')}: ${ editingUser.current_token_usage?.toLocaleString(uiLocale()) || 0 } ${t('adminDashboard.tokens')}</span>
<span :class="{'text-[var(--text-danger-strong)]': editingUser.token_usage_percentage >= 100, 'text-[var(--text-warn-strong)]': editingUser.token_usage_percentage >= 80 && editingUser.token_usage_percentage < 100}">${ editingUser.token_usage_percentage || 0 }%</span>
</div>
<div class="w-full bg-[var(--bg-tertiary)] rounded-full h-2">
@@ -1523,13 +1523,13 @@ Summarization Instructions:
${t('adminDashboard.noLimit')}
</span>
<span v-else-if="editingSetting.key === 'transcript_length_limit'">
- ${ Number(editingSetting.value).toLocaleString() } ${t('adminDashboard.characters')}
+ ${ Number(editingSetting.value).toLocaleString(uiLocale()) } ${t('adminDashboard.characters')}
</span>
<span v-else-if="editingSetting.key === 'max_file_size_mb'">
- ${ Number(editingSetting.value).toLocaleString() } ${t('adminDashboard.megabytes')}
+ ${ Number(editingSetting.value).toLocaleString(uiLocale()) } ${t('adminDashboard.megabytes')}
</span>
<span v-else-if="editingSetting.key === 'asr_timeout_seconds'">
- ${ Number(editingSetting.value).toLocaleString() } ${t('adminDashboard.seconds')} (${ Math.round(Number(editingSetting.value) / 60) } ${t('adminDashboard.minutes')})
+ ${ Number(editingSetting.value).toLocaleString(uiLocale()) } ${t('adminDashboard.seconds')} (${ Math.round(Number(editingSetting.value) / 60) } ${t('adminDashboard.minutes')})
</span>
<span v-else>${ editingSetting.value || t('adminDashboard.notSet') }</span>
</div>
@@ -1598,7 +1598,7 @@ Summarization Instructions:
</div>
</div>
<div class="text-sm text-[var(--text-muted)]">
- ${t('adminDashboard.total')}: <span class="font-medium text-[var(--text-primary)]">${ (settingTimeoutMinutes * 60 + settingTimeoutSeconds).toLocaleString() } ${t('adminDashboard.seconds')}</span>
+ ${t('adminDashboard.total')}: <span class="font-medium text-[var(--text-primary)]">${ (settingTimeoutMinutes * 60 + settingTimeoutSeconds).toLocaleString(uiLocale()) } ${t('adminDashboard.seconds')}</span>
</div>
<small class="text-[var(--text-muted)]">${t('adminDashboard.timeoutRecommendation')}</small>
</div>
@@ -2505,8 +2505,8 @@ Summarization Instructions:
const formatCompact = (n) => {
n = Number(n) || 0;
- if (n < 1000) return n.toLocaleString();
- return new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1 }).format(n);
+ if (n < 1000) return n.toLocaleString(window.i18n?.getIntlLocale());
+ return new Intl.NumberFormat(window.i18n?.getIntlLocale(), { notation: 'compact', maximumFractionDigits: 1 }).format(n);
};
const formatCost = (v) => {
v = Number(v) || 0;
@@ -2533,7 +2533,7 @@ Summarization Instructions:
const formatDay = (iso) => {
if (!iso) return '';
const [y, m, d] = String(iso).slice(0, 10).split('-').map(Number);
- return new Date(y, m - 1, d).toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' });
+ return new Date(y, m - 1, d).toLocaleDateString(window.i18n?.getIntlLocale(), { day: 'numeric', month: 'short', year: 'numeric' });
};
const _change = (cur, prev) => {
if (!prev) return cur ? _t('adminDashboard.statsPage.newInRange') : _t('adminDashboard.statsPage.noChange');
@@ -2547,16 +2547,16 @@ Summarization Instructions:
const costLocal = o.ai_cost.current === 0 && overview.value.usage.models_local;
return [
{ key: 'recordings', icon: 'fas fa-file-audio', label: _t('adminDashboard.statsPage.recordings'),
- value: o.recordings.current.toLocaleString(), note: _change(o.recordings.current, o.recordings.previous) },
+ value: o.recordings.current.toLocaleString(window.i18n?.getIntlLocale()), note: _change(o.recordings.current, o.recordings.previous) },
{ key: 'audio', icon: 'fas fa-microphone', label: _t('adminDashboard.statsPage.audioTranscribed'),
value: formatMinutes(o.audio_minutes.current), note: _change(o.audio_minutes.current, o.audio_minutes.previous) },
{ key: 'requests', icon: 'fas fa-comments', label: _t('adminDashboard.statsPage.aiRequests'),
- value: o.ai_requests.current.toLocaleString(), note: _change(o.ai_requests.current, o.ai_requests.previous) },
+ value: o.ai_requests.current.toLocaleString(window.i18n?.getIntlLocale()), note: _change(o.ai_requests.current, o.ai_requests.previous) },
{ key: 'cost', icon: 'fas fa-dollar-sign', label: _t('adminDashboard.statsPage.aiCost'),
value: costLocal ? _t('adminDashboard.tokenUsage.local') : formatCost(o.ai_cost.current),
note: costLocal ? '' : _change(o.ai_cost.current, o.ai_cost.previous) },
{ key: 'users', icon: 'fas fa-users', label: _t('adminDashboard.statsPage.activeUsers'),
- value: o.active_users.current.toLocaleString(), note: _t('adminDashboard.statsPage.ofTotal', { total: o.active_users.total }) },
+ value: o.active_users.current.toLocaleString(window.i18n?.getIntlLocale()), note: _t('adminDashboard.statsPage.ofTotal', { total: o.active_users.total }) },
{ key: 'storage', icon: 'fas fa-database', label: _t('adminDashboard.totalStorage'),
value: formatFileSize(o.storage), note: _t('adminDashboard.statsPage.allRecordings', { count: stats.value.total_recordings || 0 }) },
];
@@ -2626,6 +2626,7 @@ Summarization Instructions:
options: {
responsive: true,
maintainAspectRatio: false,
+ locale: window.i18n?.getIntlLocale(),
plugins: {
legend: { display: legend, position: 'bottom', labels: { color: textColor, boxWidth: 10, boxHeight: 10 } },
tooltip: { mode: 'index', intersect: false,
@@ -2642,7 +2643,7 @@ Summarization Instructions:
};
const _dayLabel = (iso) => {
const [y, m, d] = String(iso).split('-').map(Number);
- return new Date(y, m - 1, d).toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
+ return new Date(y, m - 1, d).toLocaleDateString(window.i18n?.getIntlLocale(), { month: 'short', day: 'numeric' });
};
const renderStatsCharts = () => {
const o = overview.value;
@@ -2669,7 +2670,7 @@ Summarization Instructions:
const months = o.usage.monthly;
const monthLabels = months.map((m, i) => {
- const name = new Date(m.year, m.month - 1, 1).toLocaleDateString(undefined, { month: 'short' });
+ const name = new Date(m.year, m.month - 1, 1).toLocaleDateString(window.i18n?.getIntlLocale(), { month: 'short' });
return i === 0 || m.month === 1 ? `${name} ${m.year}` : name;
});
_bar('statsMonthlyCostChart', monthLabels, [
@@ -2836,7 +2837,7 @@ Summarization Instructions:
// Guard against unparseable input so we never render the
// literal "Invalid Date Invalid Date".
if (isNaN(date.getTime())) return t('adminDashboard.never');
- return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
+ return date.toLocaleDateString(window.i18n?.getIntlLocale()) + ' ' + date.toLocaleTimeString(window.i18n?.getIntlLocale());
};
const getSettingDescription = (setting) => {
@@ -4053,6 +4054,8 @@ Summarization Instructions:
return {
// i18n - bind to i18n instance to maintain context
t: (key, params) => i18nInstance ? i18nInstance.t(key, params) : key,
+ // The interface locale for toLocale*String calls in the template (#480)
+ uiLocale: () => window.i18n?.getIntlLocale(),
// State
isTeamAdminOnly,
diff --git a/templates/components/detail/desktop-stats-tab.html b/templates/components/detail/desktop-stats-tab.html
index 1bec2873..7e8e43e6 100644
--- a/templates/components/detail/desktop-stats-tab.html
+++ b/templates/components/detail/desktop-stats-tab.html
@@ -19,7 +19,7 @@
</div>
<div class="bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md p-3">
<div class="t-label">${ t('stats.words') }</div>
- <div class="t-heading mt-1">${ recordingStats.total.words.toLocaleString() }</div>
+ <div class="t-heading mt-1">${ recordingStats.total.words.toLocaleString(uiLocale()) }</div>
</div>
</div>
@@ -57,7 +57,7 @@
<td class="py-2 px-3 font-mono text-right">${ row.durationLabel }</td>
<td class="py-2 px-3 text-right">${ row.pct.toFixed(1) }%</td>
<td class="py-2 px-3 text-right">${ row.turns }</td>
- <td class="py-2 px-3 text-right">${ row.words.toLocaleString() }</td>
+ <td class="py-2 px-3 text-right">${ row.words.toLocaleString(uiLocale()) }</td>
<td class="py-2 px-3 text-right">${ row.wpm || '—' }</td>
</tr>
<!-- Silence row -->
diff --git a/templates/components/detail/mobile-stats-panel.html b/templates/components/detail/mobile-stats-panel.html
index a140741b..3be390fe 100644
--- a/templates/components/detail/mobile-stats-panel.html
+++ b/templates/components/detail/mobile-stats-panel.html
@@ -22,7 +22,7 @@
</div>
<div class="bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md p-3">
<div class="t-label">${ t('stats.words') }</div>
- <div class="t-subhead mt-1" v-text="recordingStats.total.words.toLocaleString()"></div>
+ <div class="t-subhead mt-1" v-text="recordingStats.total.words.toLocaleString(uiLocale())"></div>
</div>
</div>
@@ -60,7 +60,7 @@
</div>
<div>
<div class="t-label">${ t('stats.words') }</div>
- <div class="text-sm font-medium mt-0.5" v-text="row.words.toLocaleString()"></div>
+ <div class="text-sm font-medium mt-0.5" v-text="row.words.toLocaleString(uiLocale())"></div>
</div>
</div>
<div v-if="row.wpm" class="mt-2 pt-2 border-t border-[var(--border-secondary)] flex items-center justify-between t-meta">
diff --git a/templates/components/token_budget_indicator.html b/templates/components/token_budget_indicator.html
index ddd15adc..2917bc46 100644
--- a/templates/components/token_budget_indicator.html
+++ b/templates/components/token_budget_indicator.html
@@ -5,7 +5,7 @@
:class="tokenBudget.has_budget && tokenBudget.storage && tokenBudget.storage.has_quota ? 'usage-meters--stacked' : ''">
<div v-if="tokenBudget.has_budget"
class="usage-meter flex items-center gap-1.5 px-2 py-1 rounded text-xs text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors cursor-default"
- :title="t('usageMeters.tokenTooltip', { used: (tokenBudget.usage || 0).toLocaleString(), budget: (tokenBudget.budget || 0).toLocaleString() })">
+ :title="t('usageMeters.tokenTooltip', { used: (tokenBudget.usage || 0).toLocaleString(uiLocale()), budget: (tokenBudget.budget || 0).toLocaleString(uiLocale()) })">
<i class="fas fa-coins text-[10px]"
:style="tokenBudget.percentage >= 100 ? {color: '#ef4444'} : tokenBudget.percentage >= 80 ? {color: '#f59e0b'} : {}"></i>
<span :style="tokenBudget.percentage >= 100 ? {color: '#ef4444'} : tokenBudget.percentage >= 80 ? {color: '#f59e0b'} : {}">${ tokenBudget.percentage }%</span>
diff --git a/templates/group-admin.html b/templates/group-admin.html
index 9f1fefb1..6278adfd 100644
--- a/templates/group-admin.html
+++ b/templates/group-admin.html
@@ -177,7 +177,7 @@
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-[var(--text-muted)]">
- ${ parseInstant(group.created_at).toLocaleDateString() }
+ ${ parseInstant(group.created_at).toLocaleDateString(uiLocale()) }
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium space-x-2">
<button @click="openManageTeamModal(group)" class="text-blue-500 hover:text-blue-700" title="Manage Members">
@@ -1532,6 +1532,8 @@
return {
// i18n - bind to i18n instance to maintain context
t: (key, params) => i18nInstance ? i18nInstance.t(key, params) : key,
+ // The interface locale for toLocale*String calls in the template (#480)
+ uiLocale: () => window.i18n?.getIntlLocale(),
// State
isTeamAdminOnly,
diff --git a/templates/inquire.html b/templates/inquire.html
index 343a4f9d..27be13ff 100644
--- a/templates/inquire.html
+++ b/templates/inquire.html
@@ -1197,7 +1197,7 @@
s = s.replace(' ', 'T') + 'Z';
}
const date = new Date(s);
- return date.toLocaleDateString();
+ return date.toLocaleDateString(window.i18n?.getIntlLocale());
};
// For INSTANT timestamps (e.g. share created_at): backend sends
@@ -1209,7 +1209,7 @@
s = s.replace(' ', 'T') + 'Z';
}
const date = new Date(s);
- return date.toLocaleDateString() + ' ' + date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
+ return date.toLocaleDateString(window.i18n?.getIntlLocale()) + ' ' + date.toLocaleTimeString(window.i18n?.getIntlLocale(), { hour: '2-digit', minute: '2-digit' });
};
// Smart scrolling functions
@@ -1313,6 +1313,8 @@
return {
// i18n - bind to i18n instance to maintain context
t: (key, params) => i18nInstance ? i18nInstance.t(key, params) : key,
+ // components/header-controls.html formats numbers with this (#480)
+ uiLocale: () => window.i18n?.getIntlLocale(),
// Shared header controls (components/header-controls.html)
...headerNotifications,
diff --git a/templates/modals/add-speaker-modal.html b/templates/modals/add-speaker-modal.html
index b3a64a42..7ccb325c 100644
--- a/templates/modals/add-speaker-modal.html
+++ b/templates/modals/add-speaker-modal.html
@@ -44,7 +44,7 @@
<div class="t-body-strong">${ suggestion.name }</div>
<div class="t-meta">
Used ${ suggestion.use_count } time${ suggestion.use_count !== 1 ? 's' : '' }
- <span v-if="suggestion.last_used"> • Last: ${ parseServerInstant(suggestion.last_used).toLocaleDateString() }</span>
+ <span v-if="suggestion.last_used"> • Last: ${ parseServerInstant(suggestion.last_used).toLocaleDateString(uiLocale()) }</span>
</div>
</div>
<i class="fas fa-user text-[var(--text-muted)] ml-2"></i>
diff --git a/tests/test_localization.py b/tests/test_localization.py
index 69c90524..96a44a24 100644
--- a/tests/test_localization.py
+++ b/tests/test_localization.py
@@ -212,3 +212,73 @@ def test_every_server_key_in_english_is_used():
used = _server_keys_used()
unused = sorted(k for k in _flatten(_load('en')) if k.startswith('server.') and k not in used)
assert not unused, f'server keys in en.json that no translate() call uses: {unused}'
+
+
+# Dates, times and numbers follow the interface language (#480). A
+# toLocale*String call or an Intl formatter that passes no locale, undefined,
+# [], navigator.language or a hardcoded 'en-US' uses the browser language or
+# English whatever the user selected. Numbers count too: the scanner cannot tell
+# a Date receiver from a number, and both should follow the interface locale.
+# Intl.DateTimeFormat().resolvedOptions() is time zone detection, not
+# formatting, and stays allowed.
+LOCALE_OPT_OUT = re.compile(
+ r"""(?:\.toLocale(?:Date|Time)?String"""
+ r"""|\bIntl\.(?:DateTimeFormat|NumberFormat|RelativeTimeFormat|PluralRules|ListFormat|DisplayNames))"""
+ r"""\(\s*(?:\)(?!\s*\.resolvedOptions\b)|undefined\b|\[\s*\]|navigator\.languages?\b|(['"])en-US\1)""")
+
+
+def _locale_opt_outs():
+ found = []
+ paths = list(_walk('static/js', '.js', skip=('.test.js',))) + list(_walk('templates', '.html'))
+ for path in paths:
+ text = open(path, encoding='utf-8').read()
+ for m in LOCALE_OPT_OUT.finditer(text):
+ line = text.count('\n', 0, m.start()) + 1
+ found.append(f'{os.path.relpath(path, REPO)}:{line}: {m.group(0)}')
+ return found
+
+
+def test_no_date_or_number_formatting_ignores_the_interface_locale():
+ offenders = _locale_opt_outs()
+ assert not offenders, (
+ 'locale-less date/number formatting (pass window.i18n?.getIntlLocale(), '
+ 'or uiLocale() in a Vue template):\n' + '\n'.join(f' {o}' for o in offenders))
+
+
+ 'x.toLocaleDateString(undefined, {})',
+ 'x.toLocaleTimeString([], {})',
+ 'x.toLocaleTimeString([ ], {})',
+ "x.toLocaleDateString('en-US')",
+ 'x.toLocaleDateString("en-US", {})',
+ 'x.toLocaleDateString()',
+ 'x.toLocaleTimeString()',
+ 'n.toLocaleString()',
+ 'x.toLocaleString(\n undefined, opts)',
+ 'x.toLocaleString(navigator.language)',
+ 'new Intl.NumberFormat(undefined, { notation: "compact" })',
+ 'new Intl.DateTimeFormat().format(d)',
+ "new Intl.RelativeTimeFormat('en-US')",
+])
+def test_locale_scanner_matches_the_opt_outs(call):
+ """A broken regex would make the guard above pass while checking nothing."""
+ assert LOCALE_OPT_OUT.search(call), call
+
+
+ 'x.toLocaleDateString(window.i18n?.getIntlLocale(), {})',
+ 'x.toLocaleString(uiLocale())',
+ 'x.toLocaleTimeString(locale, {})',
+ 'x.toLocaleDateString(undefinedLocale)',
+ "x.toLocaleDateString('de', {})",
+ "x.toLocaleDateString('en-GB')",
+ 'new Intl.NumberFormat(uiLocale(), {})',
+ 'Intl.DateTimeFormat().resolvedOptions().timeZone',
+ 'Intl.DateTimeFormat()\n .resolvedOptions().timeZone',
+ 'x.toLocaleUpperCase()',
+ 'a.localeCompare(b)',
+])
+def test_locale_scanner_allows_a_resolved_locale(call):
+ """The guard targets the opt-out, not every call: an explicit locale, time
+ zone detection and unrelated locale methods pass."""
+ assert not LOCALE_OPT_OUT.search(call), call