Support for translations possible? (wp.i18n)
camya opened this issue · comments
Hi,
I tried to translate the Vue Frontend, but haven't find a good way to make this possible.
Have you already worked with i18 in the boilerplate?
Best
Hi @camya ,
yes, you can do that easily.
It's not in the boilerplate code yet. I will add it today. Thanks for letting me know about it.
You can do it by following this:
$t(str) {
let translateString = WPWVTAdmin.i18n[str];
if (translateString) {
return translateString;
}
return str;
},
- Use it from your Vue or js
$t('My Text')
Thanks
Translation Support adds.
You can check the code in the latest commit.
c02d984#diff-b9f7743dad11fb515ee3f862cc1183f6a854846a210fadad57e207e64ec7cbb0
//PHP code
Just localize the string like this
add_filter('WPWVT/frontend_translatable_strings', function($translatable){
$translatable['world'] = __('World', 'wp-boilerplate-vue-with-vite');
return $translatable;
}, 10, 1);
//Vue Js code
<h1> {{ $t('world') }} </h1>
Great. Thank you for the quick update. This looks very good. Created translations with the Loco Translate plugin, and it works fine.
loved to hear that,
You are welcome.