Replies: 1 comment
-
|
Hey @supemeko! The The problem is that Here are two better ways to handle this. 1. The Easy Way: Nested
|
Beta Was this translation helpful? Give feedback.
-
|
Hey @supemeko! The The problem is that Here are two better ways to handle this. 1. The Easy Way: Nested
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How to Dynamically Reference Translation Keys in vue-i18n
I'm having trouble with
vue-i18nwhen using the@:{key}syntax for dynamic translation key references. Here's the issue:Issue
My translation dictionary is:
{ "HealthAlarm": "The Health Alarm '@:{reason}' '{name}'", "breeding_wound": "Breeding Wound" }When calling
$t('HealthAlarm', { reason: 'breeding_wound', name: 'Cow#01' }), I expect:But the actual output is:
I want to know the best approach for this.
Current Workaround
I'm using a dictionary structure like:
{ "HealthAlarm.breeding_wound": "The Health Alarm '@:dict.breeding_wound' '{name}'", "HealthAlarm.suspected_mastitis": "The Health Alarm '@:dict.suspected_mastitis' '{name}'", "dict.breeding_wound": "Breeding Wound", "dict.suspected_mastitis": "Suspected Mastitis" }or:
{ "HealthAlarm.breeding_wound": "The Health Alarm 'Breeding Wound' '{name}'", "HealthAlarm.suspected_mastitis": "The Health Alarm 'Suspected Mastitis' '{name}'", }This approach is not elegant enough
Note.1: I don’t assume that only 'reason' needs to be translated twice. The key requiring double translation could be another key, or there could be multiple keys.
Note.2: I don't expect to use a dedicated key to indicate that it will be translated twice, example '{'twice': { 'reason': 'breeding_wound' } }', Although doing so seems better than the existing solutions
Question
What is the best practice for handling dynamic translation key references in
vue-i18nwhen the backend provides a dictionary name and JSON data? Specifically:vue-i18ndictionary to avoid hardcoding keys likeHealthAlarm.breeding_woundfor better scalability?vue-i18ntranslations?Please provide code examples or recommendations for optimizing.
Beta Was this translation helpful? Give feedback.
All reactions