Closed camya closed 1 year ago
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:
Localize i18 array with translatable string like this.
Set a global method in your mixin as $t
$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. https://github.com/hasanuzzamanbe/wp-boilerplate-vue-with-vite/commit/c02d98436107caf1560e8336479c788f6af77ebd#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.
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