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 d6568b2beb
commit a32af9a8e4
3 changed files with 29 additions and 13 deletions

View File

@@ -256,11 +256,17 @@ export default {
},
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 translated = this.$t(tKey);
if (!translated || translated === tKey) return value;
return translated;
return (!translated || translated === tKey) ? key : translated;
},
openNewDirectorDialog() {

View File

@@ -252,11 +252,17 @@
});
},
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 translated = this.$t(tKey);
if (!translated || translated === tKey) return value;
return translated;
return (!translated || translated === tKey) ? key : translated;
},
},
async mounted() {
@@ -300,10 +306,10 @@
currentPrice: currentPrice
}
});
this.$set(item, 'betterPrices', data || []);
item.betterPrices = data || [];
} catch (error) {
console.error(`Error loading prices for item ${itemKey}:`, error);
this.$set(item, 'betterPrices', []);
item.betterPrices = [];
} finally {
this.loadingPrices.delete(itemKey);
}