Refactor speedLabel method across components: Enhance localization handling for speed values by adding support for object types and improving fallback logic. This change ensures more accurate translations and better user experience in displaying transport speed information.

This commit is contained in:
Torsten Schulz (local)
2026-01-29 14:22:25 +01:00
parent e7052636ba
commit 474e46837a
3 changed files with 29 additions and 13 deletions

View File

@@ -256,11 +256,17 @@ export default {
}, },
speedLabel(value) { speedLabel(value) {
const key = value == null ? 'unknown' : String(value); if (value == null) return this.$t('falukant.branch.transport.speed.unknown') || '—';
if (typeof value === 'object') {
const k = value.tr ?? value.id ?? 'unknown';
const tKey = `falukant.branch.transport.speed.${k}`;
const t = this.$t(tKey);
return (t && t !== tKey) ? t : String(k);
}
const key = String(value);
const tKey = `falukant.branch.transport.speed.${key}`; const tKey = `falukant.branch.transport.speed.${key}`;
const translated = this.$t(tKey); const translated = this.$t(tKey);
if (!translated || translated === tKey) return value; return (!translated || translated === tKey) ? key : translated;
return translated;
}, },
openNewDirectorDialog() { openNewDirectorDialog() {

View File

@@ -252,11 +252,17 @@
}); });
}, },
speedLabel(value) { speedLabel(value) {
const key = value == null ? 'unknown' : String(value); if (value == null) return this.$t('falukant.branch.transport.speed.unknown') || '—';
if (typeof value === 'object') {
const k = value.tr ?? value.id ?? 'unknown';
const tKey = `falukant.branch.transport.speed.${k}`;
const t = this.$t(tKey);
return (t && t !== tKey) ? t : String(k);
}
const key = String(value);
const tKey = `falukant.branch.transport.speed.${key}`; const tKey = `falukant.branch.transport.speed.${key}`;
const translated = this.$t(tKey); const translated = this.$t(tKey);
if (!translated || translated === tKey) return value; return (!translated || translated === tKey) ? key : translated;
return translated;
}, },
}, },
async mounted() { async mounted() {
@@ -300,10 +306,10 @@
currentPrice: currentPrice currentPrice: currentPrice
} }
}); });
this.$set(item, 'betterPrices', data || []); item.betterPrices = data || [];
} catch (error) { } catch (error) {
console.error(`Error loading prices for item ${itemKey}:`, error); console.error(`Error loading prices for item ${itemKey}:`, error);
this.$set(item, 'betterPrices', []); item.betterPrices = [];
} finally { } finally {
this.loadingPrices.delete(itemKey); this.loadingPrices.delete(itemKey);
} }

View File

@@ -719,13 +719,17 @@ export default {
}, },
speedLabel(value) { speedLabel(value) {
// Expect numeric speeds 1..4; provide localized labels as fallback to raw value if (value == null) return this.$t('falukant.branch.transport.speed.unknown') || '—';
const key = value == null ? 'unknown' : String(value); if (typeof value === 'object') {
const k = value.tr ?? value.id ?? 'unknown';
const tKey = `falukant.branch.transport.speed.${k}`;
const t = this.$t(tKey);
return (t && t !== tKey) ? t : String(k);
}
const key = String(value);
const tKey = `falukant.branch.transport.speed.${key}`; const tKey = `falukant.branch.transport.speed.${key}`;
const translated = this.$t(tKey); const translated = this.$t(tKey);
// If translation returns the key (no translation found), fall back to the numeric value return (!translated || translated === tKey) ? key : translated;
if (!translated || translated === tKey) return value;
return translated;
}, },
transportModeLabel(mode) { transportModeLabel(mode) {