mputkowski/laravel-localization

为Laravel提供强大的本地化功能

v5.0 2023-03-11 09:12 UTC

This package is auto-updated.

Last update: 2024-09-04 18:49:06 UTC


README

run-tests StyleCI Codecov Latest Stable Version Total Downloads License

Laravel本地化

安装

将包添加到composer.json文件中

composer require mputkowski/laravel-localization

发布包的配置文件

php artisan vendor:publish --provider="mputkowski\Localization\ServiceProvider"

middlewareGroups数组中的web组内包含中间件(位于app/Http/Kernel.php

'web' => [
    \mputkowski\Localization\Middleware\VerifyLangCookie::class,
],

您无需注册服务提供者和别名,此包使用自动发现。

手动安装

composer require mputkowski/laravel-localization

config/app.php中,将以下内容添加到providers数组中

'providers' => [
    mputkowski\Localization\ServiceProvider::class,
],

并在aliases数组中注册别名

'aliases' => [
    'Localization' => mputkowski\Localization\Facades\Localization::class,
],
php artisan vendor:publish --provider="mputkowski\Localization\ServiceProvider"

middlewareGroups数组中的web组内包含中间件(位于app/Http/Kernel.php

'web' => [
    \mputkowski\Localization\Middleware\VerifyLangCookie::class,
],

配置

配置存储在config/localization.php文件中。

自动检测

如果将auto设置为true,应用程序将自动检测客户端的语言。将lang目录与客户端的Accept-Language头进行比较。如果头与应用程序的区域不匹配,则语言将设置为默认语言。

可以通过访问专门为此设计的特殊路由或通过调用setLocale方法来更改自动检测到的语言

use mputkowski\Localization\Facades\Localization;

Localization::setLocale('en');

路由

此包还提供快速更改语言的路线(url: /lang/{lang},例如 /lang/en)。

贡献

请随意创建pull请求或打开问题,我会尽快查看。

许可证

此项目是开源软件,许可协议为MIT许可证

MIT License

Copyright (c) 2018 - 2024 Michał Putkowski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.