From 474e46837a7705b8b24fe21cb63d855295f89ea8 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 29 Jan 2026 14:22:25 +0100 Subject: [PATCH] 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. --- .../src/components/falukant/DirectorInfo.vue | 12 +++++++++--- frontend/src/components/falukant/SaleSection.vue | 16 +++++++++++----- frontend/src/views/falukant/BranchView.vue | 14 +++++++++----- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/falukant/DirectorInfo.vue b/frontend/src/components/falukant/DirectorInfo.vue index 446081c..c3c0609 100644 --- a/frontend/src/components/falukant/DirectorInfo.vue +++ b/frontend/src/components/falukant/DirectorInfo.vue @@ -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() { diff --git a/frontend/src/components/falukant/SaleSection.vue b/frontend/src/components/falukant/SaleSection.vue index c481234..97728c6 100644 --- a/frontend/src/components/falukant/SaleSection.vue +++ b/frontend/src/components/falukant/SaleSection.vue @@ -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); } diff --git a/frontend/src/views/falukant/BranchView.vue b/frontend/src/views/falukant/BranchView.vue index 1a6f7a6..a124bd5 100644 --- a/frontend/src/views/falukant/BranchView.vue +++ b/frontend/src/views/falukant/BranchView.vue @@ -719,13 +719,17 @@ export default { }, speedLabel(value) { - // Expect numeric speeds 1..4; provide localized labels as fallback to raw 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 translation returns the key (no translation found), fall back to the numeric value - if (!translated || translated === tKey) return value; - return translated; + return (!translated || translated === tKey) ? key : translated; }, transportModeLabel(mode) {