承接 lykegenes/laravel-locale-switcher 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lykegenes/laravel-locale-switcher

最新稳定版本:9.0.0

Composer 安装命令:

composer require lykegenes/laravel-locale-switcher

包简介

A Laravel locale switcher Middleware

README 文档

README

Latest Version on Packagist Software License Build Status Total Downloads

A Simple Laravel middleware to easily load and switch the user's locale.

Version Compatibility

Laravel Laravel Locale Switcher
5.x 1.5.x
6.x 6.x
7.x 7.x
8.x 8.x
9.x 9.x

Install

Via Composer

composer require lykegenes/laravel-locale-switcher

Then, add this to your Service Providers (It should be done automa) :

Lykegenes\LocaleSwitcher\ServiceProvider::class,

and add this Alias [Optional]

'LocaleSwitcher' => Lykegenes\LocaleSwitcher\Facades\LocaleSwitcher::class,

Finally, you will need to register this Middleware either in your Kernel.php or directly in your routes. This way, you can control which routes will have automatic locale detection (Web pages) or not (your API). Make sure this middleware is placed after any Session or Cookie related middlewares from the framework.

\Lykegenes\LocaleSwitcher\Middleware\SwitchLocaleMiddleware::class,

Optionally, you can publish and edit the configuration file :

php artisan vendor:publish --provider="Lykegenes\LocaleSwitcher\ServiceProvider" --tag=config

Usage

To change the locale, simply add "locale" to the route parameters. It works for all your routes. Some examples :

http://my-app.com/?locale=en
http://my-app.com/some/sub/route?locale=fr
http://my-app.com/some/sub/route?locale=es&otherParam=value

This will store the locale in the user's session, and set it as the current locale everytime the user requests a page.

You can build the routes with the included helpers. The URLs will be generated using the current locale.

$url = action_localized('SomeController@someFunction', ['your' => 'parameters']);
$url = route_localized('someNamedRoute', ['your' => 'parameters']);

To build a URL to the same page, but with a different locale, use the switch_locale() helper.

$url = switch_locale('fr'); // URL of the French version of the current page.

You can easily generate a dropdown using the laravelcollective/html package :

HTML::ul(LocaleSwitcher::getEnabledLocales());

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-13