Skip to content

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

Python

Format displayed percentages in the interface language with i18n.formatPercent, and fix the mobile silence line that read "12.5% % of audio" (#480, #481)

Murtaza Nasir59804d7d4650
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index b8f265a9..eb54383e 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -2026,6 +2026,8 @@ document.addEventListener('DOMContentLoaded', async () => {
// Localized number and units (#481)
// Without i18n.js (not loaded yet) the page still shows a size.
const formatFileSize = (bytes) => (window.i18n?.formatFileSize ? window.i18n.formatFileSize(bytes) : `${Number(bytes) || 0} bytes`);
+ const formatPercent = (pct, options) => (window.i18n?.formatPercent ? window.i18n.formatPercent(pct, options) : `${Math.round((Number(pct) || 0) * 10) / 10}%`);
+ const formatNumber = (n, options) => (window.i18n?.formatNumber ? window.i18n.formatNumber(n, options) : String(n));
// Parse a backend INSTANT timestamp. The backend stores/serializes
// naive UTC (no zone designator); new Date() would parse a zoneless
@@ -4482,6 +4484,8 @@ document.addEventListener('DOMContentLoaded', async () => {
// Utilities
formatFileSize,
+ formatPercent,
+ formatNumber,
// The interface locale for toLocale*String calls in templates (#480)
uiLocale: () => window.i18n?.getIntlLocale?.(),
parseServerInstant,
diff --git a/static/js/global-header.js b/static/js/global-header.js
index 7f1d2fb6..e65f5996 100644
--- a/static/js/global-header.js
+++ b/static/js/global-header.js
@@ -91,6 +91,7 @@ async function mountGlobalHeader() {
t,
// components/header-controls.html formats numbers with this (#480)
uiLocale: () => window.i18n?.getIntlLocale?.(),
+ formatPercent: (pct, options) => (window.i18n?.formatPercent ? window.i18n.formatPercent(pct, options) : `${Math.round((Number(pct) || 0) * 10) / 10}%`),
...notifications,
isUserMenuOpen,
tokenBudget,
diff --git a/static/js/i18n.js b/static/js/i18n.js
index 95519a01..597550a0 100644
--- a/static/js/i18n.js
+++ b/static/js/i18n.js
@@ -268,6 +268,20 @@ class I18n {
return new Intl.NumberFormat(this.getIntlLocale(), options).format(number);
}
+ /**
+ * Format a percentage in the interface language: "12.5%", "12,5 %" in
+ * German (#480). The value is on the 0-100 scale, as every caller holds
+ * it: formatPercent(12.5) is 12.5 %, not 1250 %.
+ * @param {number} percent - Percentage, 0-100 (more is allowed)
+ * @param {object} options - Intl.NumberFormat options; at most one decimal by default
+ * @returns {string} Formatted percentage
+ */
+ formatPercent(percent, options = {}) {
+ const value = Number(percent);
+ return this.formatNumber(Number.isFinite(value) ? value / 100 : 0,
+ { maximumFractionDigits: 1, ...options, style: 'percent' });
+ }
+
/**
* Format file size with appropriate unit, at most one decimal, in the
* interface language's number format: "1.5 MB", "1,5 MB" in German (#481).
diff --git a/static/js/i18n.test.js b/static/js/i18n.test.js
index ca42b85e..802e71ad 100644
--- a/static/js/i18n.test.js
+++ b/static/js/i18n.test.js
@@ -186,3 +186,36 @@ describe('file sizes (#481)', () => {
for (const value of [null, undefined, NaN, 'x', -5]) expect(en.formatFileSize(value)).toBe('0 B');
});
});
+
+describe('percentages (#480)', () => {
+ const pct = (code) => load({ bootstrap: { locale: code, translations: { en: EN } } }).i18n;
+ // ICU puts a no-break space (U+00A0) or a narrow one (U+202F) before % in some languages.
+ const plain = (s) => s.replace(/[\u00a0\u202f]/g, ' ');
+
+ it('uses the separator and the % spacing of the interface language', () => {
+ expect(pct('en').formatPercent(12.5)).toBe('12.5%');
+ expect(plain(pct('de').formatPercent(12.5))).toBe('12,5 %');
+ expect(plain(pct('fr').formatPercent(12.5))).toBe('12,5 %');
+ expect(plain(pct('es').formatPercent(12.5))).toBe('12,5 %');
+ expect(plain(pct('ru').formatPercent(12.5))).toBe('12,5 %');
+ expect(pct('pt-BR').formatPercent(12.5)).toBe('12,5%');
+ expect(pct('zh').formatPercent(12.5)).toBe('12.5%');
+ });
+
+ it('takes the value on the 0-100 scale with at most one decimal by default', () => {
+ const en = pct('en');
+ expect(en.formatPercent(0)).toBe('0%');
+ expect(en.formatPercent(100)).toBe('100%');
+ expect(en.formatPercent(150)).toBe('150%');
+ expect(en.formatPercent(33.333)).toBe('33.3%');
+ expect(en.formatPercent(7)).toBe('7%');
+ expect(en.formatPercent(12.345, { maximumFractionDigits: 2 })).toBe('12.35%');
+ });
+
+ it('signs a change when asked and reads an invalid value as zero', () => {
+ const en = pct('en');
+ expect(en.formatPercent(12, { signDisplay: 'exceptZero' })).toBe('+12%');
+ expect(en.formatPercent(-4, { signDisplay: 'exceptZero' })).toBe('-4%');
+ for (const value of [null, undefined, NaN, 'x']) expect(en.formatPercent(value)).toBe('0%');
+ });
+});
diff --git a/static/js/modules/composables/speaker-modal.js b/static/js/modules/composables/speaker-modal.js
index 20c28e5f..d1710c23 100644
--- a/static/js/modules/composables/speaker-modal.js
+++ b/static/js/modules/composables/speaker-modal.js
@@ -117,7 +117,8 @@ export function useSpeakerModal(state, utils) {
const agg = speakerStats.value.bySpeaker[id];
if (!agg) return t('speakerModal.noSegmentsYet');
if (!speakerStats.value.hasTimes) return tc('speakerModal.segmentCount', agg.segments, { count: agg.segments });
- return t('speakerModal.speakingTime', { time: formatClock(agg.seconds), share: agg.share });
+ const share = window.i18n?.formatNumber ? window.i18n.formatNumber(agg.share) : agg.share;
+ return t('speakerModal.speakingTime', { time: formatClock(agg.seconds), share });
};
const speakerShare = (id) => speakerStats.value.bySpeaker[id]?.share || 0;
diff --git a/static/locales/de.json b/static/locales/de.json
index d3ca49dc..82270c00 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -2008,6 +2008,7 @@
"speaker": "Sprecher",
"time": "Zeit",
"pctAudio": "% des Audios",
+ "pctOfAudio": "{{pct}} des Audios",
"wpm": "WpM",
"silence": "Stille",
"noStatsTitle": "Noch keine Statistiken",
diff --git a/static/locales/en.json b/static/locales/en.json
index f425467a..ef796372 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -2008,6 +2008,7 @@
"speaker": "Speaker",
"time": "Time",
"pctAudio": "% of audio",
+ "pctOfAudio": "{{pct}} of audio",
"wpm": "WPM",
"silence": "Silence",
"noStatsTitle": "No stats yet",
diff --git a/static/locales/es.json b/static/locales/es.json
index 2a940aeb..425dc2dd 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -2008,6 +2008,7 @@
"speaker": "Hablante",
"time": "Tiempo",
"pctAudio": "% del audio",
+ "pctOfAudio": "{{pct}} del audio",
"wpm": "PPM",
"silence": "Silencio",
"noStatsTitle": "Aún no hay estadísticas",
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 2d12b9d9..221911c7 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -2008,6 +2008,7 @@
"speaker": "Intervenant",
"time": "Temps",
"pctAudio": "% de l'audio",
+ "pctOfAudio": "{{pct}} de l'audio",
"wpm": "MPM",
"silence": "Silence",
"noStatsTitle": "Pas encore de statistiques",
diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.json
index 44c41292..0e0d9b5a 100644
--- a/static/locales/pt-BR.json
+++ b/static/locales/pt-BR.json
@@ -2008,6 +2008,7 @@
"speaker": "Locutor",
"time": "Tempo",
"pctAudio": "% do áudio",
+ "pctOfAudio": "{{pct}} do áudio",
"wpm": "PPM",
"silence": "Silêncio",
"noStatsTitle": "Ainda não há estatísticas",
diff --git a/static/locales/ru.json b/static/locales/ru.json
index 50ca7baa..f26066f3 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -2008,6 +2008,7 @@
"speaker": "Говорящий",
"time": "Время",
"pctAudio": "% аудио",
+ "pctOfAudio": "{{pct}} аудио",
"wpm": "слов/мин",
"silence": "Тишина",
"noStatsTitle": "Статистики пока нет",
diff --git a/static/locales/zh.json b/static/locales/zh.json
index fb0b52ec..4873e07e 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -2008,6 +2008,7 @@
"speaker": "发言人",
"time": "时间",
"pctAudio": "占音频比例",
+ "pctOfAudio": "占音频 {{pct}}",
"wpm": "字/分",
"silence": "静默",
"noStatsTitle": "暂无统计数据",
diff --git a/templates/admin.html b/templates/admin.html
index 96900ba4..0d86d0db 100644
--- a/templates/admin.html
+++ b/templates/admin.html
@@ -354,7 +354,7 @@
<div>
<p class="text-xs text-[var(--text-muted)]">${t('adminDashboard.statsPage.failureRate')}</p>
<p class="font-semibold" :class="overview && overview.activity.failed ? 'text-[var(--text-danger-strong)]' : 'text-[var(--text-primary)]'"
- v-text="overview && overview.activity.failure_rate != null ? t('adminDashboard.statsPage.failedOf', { failed: overview.activity.failed, total: overview.activity.created, pct: overview.activity.failure_rate }) : '—'"></p>
+ v-text="overview && overview.activity.failure_rate != null ? t('adminDashboard.statsPage.failedOf', { failed: overview.activity.failed, total: overview.activity.created, pct: formatNumber(overview.activity.failure_rate, { maximumFractionDigits: 1 }) }) : '—'"></p>
</div>
</div>
</div>
@@ -1158,7 +1158,7 @@ Summarization Instructions:
<div class="w-full bg-[var(--bg-tertiary)] rounded-full h-2.5">
<div class="bg-[var(--text-accent)] h-2.5 rounded-full" :style="{width: getProcessingProgress() + '%'}"></div>
</div>
- <p class="text-xs text-[var(--text-muted)] mt-1">${ getProcessingProgress() }% ${t('adminDashboard.complete')}</p>
+ <p class="text-xs text-[var(--text-muted)] mt-1">${ formatPercent(getProcessingProgress()) } ${t('adminDashboard.complete')}</p>
</div>
</div>
<i class="fas fa-tasks text-3xl text-[var(--text-accent)] opacity-50"></i>
@@ -1424,7 +1424,7 @@ Summarization Instructions:
<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(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>
+ <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}">${ formatPercent(editingUser.token_usage_percentage || 0) }</span>
</div>
<div class="w-full bg-[var(--bg-tertiary)] rounded-full h-2">
<div class="h-2 rounded-full" :class="{'bg-[var(--text-danger-strong)]': editingUser.token_usage_percentage >= 100, 'bg-[var(--text-warn-strong)]': editingUser.token_usage_percentage >= 80 && editingUser.token_usage_percentage < 100, 'bg-[var(--text-success-strong)]': editingUser.token_usage_percentage < 80}" :style="{width: Math.min(editingUser.token_usage_percentage || 0, 100) + '%'}"></div>
@@ -1438,7 +1438,7 @@ Summarization Instructions:
<div v-if="editingUser.monthly_transcription_budget && editingUser.current_transcription_usage !== undefined" class="mt-2">
<div class="flex justify-between text-xs text-[var(--text-muted)] mb-1">
<span>${t('adminDashboard.currentUsageMinutes')}: ${ editingUser.current_transcription_usage_minutes || 0 } ${t('adminDashboard.minutes')}</span>
- <span :class="{'text-[var(--text-danger-strong)]': editingUser.transcription_usage_percentage >= 100, 'text-[var(--text-warn-strong)]': editingUser.transcription_usage_percentage >= 80 && editingUser.transcription_usage_percentage < 100}">${ editingUser.transcription_usage_percentage || 0 }%</span>
+ <span :class="{'text-[var(--text-danger-strong)]': editingUser.transcription_usage_percentage >= 100, 'text-[var(--text-warn-strong)]': editingUser.transcription_usage_percentage >= 80 && editingUser.transcription_usage_percentage < 100}">${ formatPercent(editingUser.transcription_usage_percentage || 0) }</span>
</div>
<div class="w-full bg-[var(--bg-tertiary)] rounded-full h-2">
<div class="h-2 rounded-full" :class="{'bg-[var(--text-danger-strong)]': editingUser.transcription_usage_percentage >= 100, 'bg-[var(--text-warn-strong)]': editingUser.transcription_usage_percentage >= 80 && editingUser.transcription_usage_percentage < 100, 'bg-[var(--text-success-strong)]': editingUser.transcription_usage_percentage < 80}" :style="{width: Math.min(editingUser.transcription_usage_percentage || 0, 100) + '%'}"></div>
@@ -1453,7 +1453,7 @@ Summarization Instructions:
<div class="mt-2">
<div class="flex justify-between text-xs text-[var(--text-muted)] mb-1">
<span>${t('adminDashboard.storageUsedLabel')}: ${ formatFileSize(editingUser.storage_used || 0) }</span>
- <span v-if="editingUser.storage_quota_mb" :class="storagePctClass(storagePct(editingUser))">${ storagePct(editingUser) }%</span>
+ <span v-if="editingUser.storage_quota_mb" :class="storagePctClass(storagePct(editingUser))">${ formatPercent(storagePct(editingUser)) }</span>
</div>
<div v-if="editingUser.storage_quota_mb" class="w-full bg-[var(--bg-tertiary)] rounded-full h-2">
<div class="h-2 rounded-full" :class="budgetBarClass(storagePct(editingUser))" :style="{width: Math.min(storagePct(editingUser), 100) + '%'}"></div>
@@ -2539,7 +2539,11 @@ Summarization Instructions:
if (!prev) return cur ? _t('adminDashboard.statsPage.newInRange') : _t('adminDashboard.statsPage.noChange');
const pct = Math.round((cur - prev) / prev * 100);
if (pct === 0) return _t('adminDashboard.statsPage.noChange');
- return _t('adminDashboard.statsPage.vsPrevious', { pct: (pct > 0 ? '+' : '') + pct + '%' });
+ return _t('adminDashboard.statsPage.vsPrevious', {
+ pct: window.i18n?.formatPercent
+ ? window.i18n.formatPercent(pct, { signDisplay: 'exceptZero' })
+ : (pct > 0 ? '+' : '') + pct + '%',
+ });
};
const overviewCards = computed(() => {
const o = overview.value && overview.value.overview;
@@ -3500,6 +3504,8 @@ Summarization Instructions:
// Localized number and units (#481)
// Without i18n.js (not loaded yet) the page still shows a size.
const formatFileSize = (bytes) => (window.i18n?.formatFileSize ? window.i18n.formatFileSize(bytes) : `${Number(bytes) || 0} bytes`);
+ const formatPercent = (pct, options) => (window.i18n?.formatPercent ? window.i18n.formatPercent(pct, options) : `${Math.round((Number(pct) || 0) * 10) / 10}%`);
+ const formatNumber = (n, options) => (window.i18n?.formatNumber ? window.i18n.formatNumber(n, options) : String(n));
const toggleDarkMode = () => {
isDarkMode.value = !isDarkMode.value;
@@ -4164,6 +4170,8 @@ Summarization Instructions:
toggleAdminStatus,
togglePublicSharingPermission,
formatFileSize,
+ formatPercent,
+ formatNumber,
toggleDarkMode,
// Group Management methods
diff --git a/templates/components/detail/desktop-stats-tab.html b/templates/components/detail/desktop-stats-tab.html
index 7e8e43e6..f86f9533 100644
--- a/templates/components/detail/desktop-stats-tab.html
+++ b/templates/components/detail/desktop-stats-tab.html
@@ -55,7 +55,7 @@
</div>
</td>
<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">${ formatPercent(row.pct) }</td>
<td class="py-2 px-3 text-right">${ row.turns }</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>
@@ -70,7 +70,7 @@
</div>
</td>
<td class="py-2 px-3 font-mono text-right">${ recordingStats.silence.durationLabel }</td>
- <td class="py-2 px-3 text-right">${ recordingStats.silence.pct.toFixed(1) }%</td>
+ <td class="py-2 px-3 text-right">${ formatPercent(recordingStats.silence.pct) }</td>
<td class="py-2 px-3 text-right text-[var(--text-muted)]">—</td>
<td class="py-2 px-3 text-right text-[var(--text-muted)]">—</td>
<td class="py-2 px-3 text-right text-[var(--text-muted)]">—</td>
diff --git a/templates/components/detail/mobile-stats-panel.html b/templates/components/detail/mobile-stats-panel.html
index 3be390fe..a72ba155 100644
--- a/templates/components/detail/mobile-stats-panel.html
+++ b/templates/components/detail/mobile-stats-panel.html
@@ -52,7 +52,7 @@
<div class="grid grid-cols-3 gap-2 text-center">
<div>
<div class="t-label">${ t('stats.pctAudio') }</div>
- <div class="text-sm font-medium mt-0.5">${ row.pct.toFixed(1) }%</div>
+ <div class="text-sm font-medium mt-0.5">${ formatPercent(row.pct) }</div>
</div>
<div>
<div class="t-label">${ t('stats.turns') }</div>
@@ -79,9 +79,8 @@
<div class="h-1.5 w-full rounded-full bg-[var(--bg-tertiary)] overflow-hidden mb-2">
<div class="h-full" :style="{ width: recordingStats.silence.pct.toFixed(1) + '%', background: 'var(--text-muted)' }"></div>
</div>
- <div class="t-meta text-center">
- ${ recordingStats.silence.pct.toFixed(1) }% ${ t('stats.pctAudio') }
- </div>
+ <div class="t-meta text-center"
+ v-text="t('stats.pctOfAudio', { pct: formatPercent(recordingStats.silence.pct) })"></div>
</div>
</div>
</div>
diff --git a/templates/components/progress-popup.html b/templates/components/progress-popup.html
index a5933b91..654db788 100644
--- a/templates/components/progress-popup.html
+++ b/templates/components/progress-popup.html
@@ -99,7 +99,7 @@
]"></i>
<span class="text-xs font-medium truncate flex-1 text-[var(--text-primary)]">${item.title}</span>
<span v-if="item.status === 'uploading' && item.progress !== null"
- class="text-xs font-bold text-blue-500">${item.progress}%</span>
+ class="text-xs font-bold text-blue-500">${ formatPercent(item.progress) }</span>
<span v-else :class="[
'text-xs font-medium px-1.5 py-0.5 rounded',
item.status === 'uploading' ? 'bg-blue-500/20 text-blue-500' :
diff --git a/templates/components/token_budget_indicator.html b/templates/components/token_budget_indicator.html
index 2917bc46..5524c943 100644
--- a/templates/components/token_budget_indicator.html
+++ b/templates/components/token_budget_indicator.html
@@ -8,7 +8,7 @@
: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>
+ <span :style="tokenBudget.percentage >= 100 ? {color: '#ef4444'} : tokenBudget.percentage >= 80 ? {color: '#f59e0b'} : {}">${ formatPercent(tokenBudget.percentage) }</span>
<div class="w-12 h-1 bg-[var(--bg-tertiary)] rounded-full overflow-hidden">
<div class="h-full rounded-full transition-all duration-300 bg-[var(--text-accent)]"
:style="{
@@ -23,7 +23,7 @@
:title="t('usageMeters.storageTooltip', { used: tokenBudget.storage.used_label, quota: tokenBudget.storage.quota_label })">
<i class="fas fa-hdd text-[10px]"
:style="tokenBudget.storage.percentage >= 100 ? {color: '#ef4444'} : tokenBudget.storage.percentage >= 80 ? {color: '#f59e0b'} : {}"></i>
- <span :style="tokenBudget.storage.percentage >= 100 ? {color: '#ef4444'} : tokenBudget.storage.percentage >= 80 ? {color: '#f59e0b'} : {}">${ tokenBudget.storage.percentage }%</span>
+ <span :style="tokenBudget.storage.percentage >= 100 ? {color: '#ef4444'} : tokenBudget.storage.percentage >= 80 ? {color: '#f59e0b'} : {}">${ formatPercent(tokenBudget.storage.percentage) }</span>
<div class="w-12 h-1 bg-[var(--bg-tertiary)] rounded-full overflow-hidden">
<div class="h-full rounded-full transition-all duration-300 bg-[var(--text-accent)]"
:style="{
diff --git a/templates/inquire.html b/templates/inquire.html
index d95870f8..1aa6a26f 100644
--- a/templates/inquire.html
+++ b/templates/inquire.html
@@ -611,12 +611,12 @@
conversation context is, so compaction never
feels like silent memory loss. -->
<span v-if="contextUsage >= 50" class="flex items-center gap-1.5"
- :title="'Conversation context: ' + contextUsage + '% — older messages are summarized when it fills up'">
+ :title="'Conversation context: ' + formatPercent(contextUsage) + ' — older messages are summarized when it fills up'">
<span class="inline-block w-16 h-1 rounded-full overflow-hidden" style="background: var(--bg-tertiary);">
<span class="block h-full rounded-full"
:style="{ width: contextUsage + '%', background: 'var(--bg-accent)' }"></span>
</span>
- <span v-text="contextUsage + '%'"></span>
+ <span v-text="formatPercent(contextUsage)"></span>
</span>
<span v-if="hasActiveFilters" style="color: var(--text-accent);">
<i class="fas fa-filter mr-1"></i>${t('inquire.filtersActive')}
@@ -1315,6 +1315,7 @@
t: (key, params) => i18nInstance ? i18nInstance.t(key, params) : key,
// components/header-controls.html formats numbers with this (#480)
uiLocale: () => window.i18n?.getIntlLocale?.(),
+ formatPercent: (pct, options) => (window.i18n?.formatPercent ? window.i18n.formatPercent(pct, options) : `${Math.round((Number(pct) || 0) * 10) / 10}%`),
// Shared header controls (components/header-controls.html)
...headerNotifications,
diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.html
index 6abd1929..d19b9e33 100644
--- a/templates/modals/speaker-modal.html
+++ b/templates/modals/speaker-modal.html
@@ -143,10 +143,10 @@
@mousedown.prevent
@click="chooseName(entry.id, topVoiceMatch(entry.id).name)"
class="spk-voice-pill"
- :title="t('speakerModal.voiceMatchTitle', { name: topVoiceMatch(entry.id).name, similarity: topVoiceMatch(entry.id).similarity })">
+ :title="t('speakerModal.voiceMatchTitle', { name: topVoiceMatch(entry.id).name, similarity: formatNumber(topVoiceMatch(entry.id).similarity) })">
<i class="fas fa-waveform-lines text-[9px]"></i>
<span class="truncate max-w-[80px]">${ topVoiceMatch(entry.id).name }</span>
- <span class="opacity-75">${ topVoiceMatch(entry.id).similarity }%</span>
+ <span class="opacity-75">${ formatPercent(topVoiceMatch(entry.id).similarity) }</span>
</button>
</div>
@@ -162,7 +162,7 @@
@click="chooseName(entry.id, option.name)">
<i class="fas" :class="option.source === 'voice' ? 'fa-waveform-lines' : 'fa-user'"></i>
<span class="spk-option-name">${ option.name }</span>
- <span v-if="option.source === 'voice'" class="t-meta" v-text="t('speakerModal.voiceMatch') + ' ' + option.similarity + '%'"></span>
+ <span v-if="option.source === 'voice'" class="t-meta" v-text="t('speakerModal.voiceMatch') + ' ' + formatPercent(option.similarity)"></span>
<span v-else-if="option.taken" class="t-meta" v-text="t('speakerModal.alreadyAssigned')"></span>
<span v-else class="t-meta" v-text="tc('speakerModal.usedTimes', option.useCount, { count: option.useCount })"></span>
</li>
diff --git a/tests/test_localization.py b/tests/test_localization.py
index 1f09ba0b..14ff9467 100644
--- a/tests/test_localization.py
+++ b/tests/test_localization.py
@@ -371,6 +371,38 @@ def test_unguarded_i18n_call_scanner(snippet, matches):
assert bool(UNGUARDED_I18N_CALL.search(snippet)) is matches
+# Percentages shown as text follow the interface language too (#480): a
+# template that writes ${ x }% or ${ x.toFixed(1) }%, or appends '%' in a
+# v-text or :title, shows "12.5%" in German. formatPercent() (i18n.formatPercent)
+# gives "12,5 %". Bar widths (:style, style=) are layout and stay as they are.
+PERCENT_TEXT = re.compile(r"""\$\{[^}]*\}\s*%|(?:v-text|:title|:aria-label)="[^"]*\+\s*'%""")
+
+
+def test_no_percentage_text_ignores_the_interface_locale():
+ offenders = []
+ for path in _walk('templates', '.html'):
+ text = open(path, encoding='utf-8').read()
+ for m in PERCENT_TEXT.finditer(text):
+ line = text[text.rfind(chr(10), 0, m.start()) + 1:text.find(chr(10), m.end())]
+ if 'window.i18n?.formatPercent ?' in line:
+ continue # the fallback of a guarded formatPercent, for a page without i18n.js
+ offenders.append(f'{os.path.relpath(path, REPO)}:{text.count(chr(10), 0, m.start()) + 1}: {m.group(0)}')
+ assert not offenders, 'format percentages with formatPercent():\n' + '\n'.join(f' {o}' for o in offenders)
+
+
[email protected]('snippet,matches', [
+ ('<span>${ row.pct.toFixed(1) }%</span>', True),
+ ('<span>${ tokenBudget.percentage }%</span>', True),
+ ("""<span v-text="contextUsage + '%'"></span>""", True),
+ (':title="\'Context: \' + contextUsage + \'% used\'"', True),
+ ('<span>${ formatPercent(row.pct) }</span>', False),
+ (':style="{ width: row.pct + \'%\' }"', False),
+ ('style="width: {{ [pct, 100]|min }}%"', False),
+])
+def test_percentage_text_scanner(snippet, matches):
+ assert bool(PERCENT_TEXT.search(snippet)) is matches
+
+
def test_every_locale_has_every_file_size_unit():
units = {'bytes', 'kilobytes', 'megabytes', 'gigabytes', 'terabytes'}
for lang in _languages():