0👍
You can define two messages:
const messages = {
en: {
message: {
world: '{msg} world',
helloWorld: 'Hello world'
}
}
}
Usage:
<!-- Use the translation without format syntax -->
<p>{{ $t('message.helloWorld' }}</p>
<!-- result: <p>Hello world</p> -->
<!-- Input the second param when you need it -->
<p>{{ $t('message.world', { msg: 'Goodbye' }) }}</p>
<!-- result: <p>Goodbye world</p> -->
- [Vuejs]-Formatting json file with vue.js
- [Vuejs]-Installing global npm package (@vue/cli) in Node v10.9 also installs Node v10.8?
0👍
You could create yourself a custom $t2
method (or alike), which supersets the basic $t
with a default param injection.
Clearly not sure that it’s worth the hassle since it will not benefit from i18n’s devtools hints (which are quite handy for sure) and is not worth the "time gained".
I’d stick to regular approach and put the effort into writing that manually when needed. Or stick to a hardcoded approach if no variable is needed.
- [Vuejs]-Assigning stream to a variable from getUserMedia()
- [Vuejs]-Vue App ID causing issues with existing page 'addEventListener'
-1👍
I found the method.
use Linked messages
defined the default value and use in each text
{
name: 'Jacky',
variable: 'Hello @:name'
}
- [Vuejs]-VueJS importing local and external script and css files in main file
- [Vuejs]-Import a javaScript file in vuejs2 project
Source:stackexchange.com