Laravel and Vue Translation Package
Published on by Paul Redmond
Laravel Vue i18n is a package by Francisco Madeira that allows you to connect your Laravel translation files with Vue projects:
Yesterday I built a localization packaged based on #Laravel to use with @vuejs 3 applications.
— Francisco Madeira (@xiCO2k) November 18, 2021
Personally I've been using it with @inertiajs.
Check it out here:https://t.co/T44B1ACbWx
This package uses the same logic as the built-in localization features:
<h1>{{ $t('Welcome :name!', { name: 'Francisco' }) }}. </h1><div> Logged in {{ $tChoice('{1} :count minute ago|[2,*] :count minutes ago', 10) }}</div>
Here are a few more examples of the package's API from the readme:
/*// lang/pt.json{ "Welcome!": "Bem-vindo!", "Welcome, :name!": "Bem-vindo, :name!", "There is one apple|There are many apples": "Existe uma maça|Existe muitas maças", "{0} There are none|[1,19] There are some|[20,*] There are many": "Não tem|Tem algumas|Tem muitas", "{1} :count minute ago|[2,*] :count minutes ago": "{1} há :count minuto|[2,*] há :count minutos",}*/ import { trans } from 'laravel-vue-i18n'; trans('Welcome!'); // Bem-vindo!trans('Welcome, :name!', { name: 'Francisco' }) // Bem-vindo Francisco!trans('Welcome, :NAME!', { name: 'Francisco' }) // Bem-vindo FRANCISCO! transChoice('There is one apple|There are many apples', 1); // Existe uma maçatransChoice('{0} There are none|[1,19] There are some|[20,*] There are many', 19); // Tem algumastransChoice('{1} :count minute ago|[2,*] :count minutes ago', 10); // Há 10 minutos.
This package allows you to change the locale at runtime via the loadLanguageAsync()
function. You can learn more about this package, get full installation instructions, and view the source code on GitHub.