Laravel 和 Vue 翻译包
发布于 作者 Paul Redmond
Laravel Vue i18n 是由 Francisco Madeira 开发的一个包,它允许你将 Laravel 翻译文件与 Vue 项目连接起来。
昨天我构建了一个基于 #Laravel 的本地化包,用于 @vuejs 3 应用程序。
— Francisco Madeira (@xiCO2k) 2021 年 11 月 18 日
我个人一直将它与 @inertiajs 一起使用。
请在这里查看:https://t.co/T44B1ACbWx
此包使用与内置本地化功能相同的逻辑。
<h1>{{ $t('Welcome :name!', { name: 'Francisco' }) }}. </h1><div> Logged in {{ $tChoice('{1} :count minute ago|[2,*] :count minutes ago', 10) }}</div>
以下是一些来自 自述文件 的包 API 的示例。
/*// 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.
此包允许你通过 loadLanguageAsync()
函数在运行时更改语言环境。 你可以在 GitHub 上了解有关此包的更多信息,获取完整的安装说明并查看 源代码。