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:
@@ -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() {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user