vue-i18n
vue-i18n copied to clipboard
Linked messages seems like not to work with variable interpolation
Reporting a bug?
Seems like you can't use variable interpolation to reference another key using linked message syntax.
Expected behavior
You should be able to do it since variable interpolation and linked messages does work separately in the same key.
Reproduction
Some locale content
{
"key1": "Example to describe @:{what}",
"key2": "the problem",
"key3": "the solution"
}
Vue template where you use i18n
<p> {{ t('key1', { what: someCondition ? 'key2' : 'key3' }) }} </p>
Output no matter what someCondition
evaluates to:
<p> Example to describe </p>
System Info
System:
OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
CPU: (12) x64 Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
Memory: 8.83 GB / 15.34 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
Browsers:
Chrome: 107.0.5304.68
npmPackages:
vue-eslint-parser: 9.1.0 => 9.1.0
Screenshot
No response
Additional context
A workaround to currently do it exists but is quite messy in my opinion: You replace the linked message by a simple interpolation and you localize the extra bit outside.
{
"key1": "Example to describe {what}",
"key2": "the problem",
"key3": "the solution"
}
<p> {{ t('key1', { what: someCondition ? t('key2') : t('key3') }) }} </p>
Validations
- [X] Read the Contributing Guidelines
- [X] Read the Documentation
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion
- [X] The provided reproduction is a minimal reproducible example of the bug.
Any updates regarding this? As mentioned in vue2-i18n repo, this should work in vue-i18n v9.x.