syscover/langlocale
最新稳定版本:v3.0.9
Composer 安装命令:
composer create-project syscover/langlocale
包简介
NavTools package
README 文档
README
Installation
1 - From the command line run
composer require syscover/laravel-nav-tools
2 - Register service provider, on file config/app.php add to providers array
Syscover\NavTools\NavToolsServiceProvider::class,
3 - To publish package, you must type on console
php artisan vendor:publish --provider="Syscover\NavTools\NavToolsServiceProvider"
4 - Register middlewares pulsar.navTools on file app/Http/Kernel.php add to routeMiddleware array
'pulsar.navTools' => \Syscover\NavTools\Middleware\NavTools::class,
General configuration environment values
Set NAVTOOLS_URL_TYPE options on environment file .env
Set url type for you web, you have three types, lang, country or lang-country, for urls type lang:
NAVTOOLS_URL_TYPE=lang
you can work with this urls
hrrp://mydomain.com/en/any-page
for urls type country
NAVTOOLS_URL_TYPE=country
you can work with this urls
hrrp://mydomain.com/us/any-page
for urls type lang-country
NAVTOOLS_URL_TYPE=lang-country
you can work with this urls
hrrp://mydomain.com/en-us/any-page
Set NAVTOOLS_LANGS options on environment file .env
Set countries available in your web
NAVTOOLS_LANGS=en|es
Set NAVTOOLS_COUNTRIES options on environment file .env
Set countries available in your web
NAVTOOLS_COUNTRIES=us|gb|es
Set NAVTOOLS_DEFAULT_COUNTRY options on environment file .env
Set default country for your web
NAVTOOLS_DEFAULT_COUNTRY=es
Routing with NavTools
On app\Http\routes.php file use this closure to implement routes with translation
Route::group(['middleware' => ['pulsar.navTools']], function() {
// write here your routes
});
Route configuration
You have several url configuration options depends on the chosen NAVTOOLS_URL_TYPE parameter:
Write your routes with lang variable
Route::group(['middleware' => ['pulsar.navTools']], function() {
Route::get('/', function(){ return view('www.index'); });
Route::get('{lang}', function(){ return view('www.index'); });
Route::post('{lang}/contact', ['as'=>'contact', 'uses'=>'FrontEndController@contact']);
});
Or set lang variable on your routes
Route::group(['middleware' => ['pulsar.navTools']], function() {
Route::get('/', function(){ return view('www.index'); });
Route::get('en', function(){ return view('www.index'); });
Route::get('es', function(){ return view('www.index'); });
Route::post('en/contact', ['as' => 'contact-en', 'uses'=>'FrontEndController@contact']);
Route::post('es/contacto', ['as' => 'contact-es', 'uses'=>'FrontEndController@contact']);
});
Or set constant lang but country variable
Route::group(['middleware' => ['pulsar.navTools']], function() {
Route::get('/', function(){ return view('www.index'); });
Route::get('/en-{country}', function(){ return view('www.index'); });
Route::get('/es-{country}', function(){ return view('www.index'); });
Route::post('en-{country}'/contact', ['as' => 'contact-en', 'uses'=>'FrontEndController@contact']);
Route::post('es-{country}'/contacto', ['as' => 'contact-es', 'uses'=>'FrontEndController@contact']);
});
Or use lang and country variables to get language value.
Route::group(['middleware' => ['pulsar.navTools']], function() {
Route::get('/', function(){ return view('www.index'); });
Route::get('/{lang}-{country}', function(){ return view('www.index'); });
Route::post('/{lang}-{country}/contact', ['as' => 'contact-en', 'uses'=>'FrontEndController@contact']);
});
Get values in your application
You can get lang and country values with this helpers.
user_country(); // to get country user
user_lang(); // to get language user
To set routes you need to add lang or country parameters depending on NAVTOOLS_URL_TYPE.
route('routeName', ['lang' => 'en', 'country' => 'us']);
You can use a custom helper nt_route(), this helper inserts automatically variables lang and country, unless you specify these variables.
nt_route('routeName');
You can use redirect() helper without any trouble, we have extended Laravel core so that redirect()->route() does the same as nt_route().
If you want to change the language or the country you must use this helpers
change_language('en');
change_country('us');
License
The NavTools is open-sourced software licensed under the MIT license.
syscover/langlocale 适用场景与选型建议
syscover/langlocale 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 151 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「locale」 「language」 「laravel」 「set language」 「set country」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 syscover/langlocale 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 syscover/langlocale 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 syscover/langlocale 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
Store your language lines in the database, yaml or other sources
Set Links with a specific language parameter
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
统计信息
- 总下载量: 151
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-30