langnonymous/lang
Composer 安装命令:
composer require langnonymous/lang
包简介
Simple Package Language To Laravel
README 文档
README
A Simple Translate To convert ui and local language. Creation and development By PhpAnonymous ( phpanonymous.com ) Laravel Version 5 and Above
##Install with Composer
composer require Langnonymous/Lang
Provider Class
this provider is auto registred
Langnonymous\Lang\Langnonymous::class,
#Aliases this aliases auto registred
'L' => Langnonymous\Lang\Lang::class,
#publish
with composer run this command php artisan vendor:publish
now you can check this file langnonymous.php on config path
you should add this middleware in kernel.php file
'Lang' => \Langnonymous\Lang\Lang::class, // like This protected $routeMiddleware = [ 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'Lang' => \Langnonymous\Lang\Lang::class, ];
#usage
you can use The L Class anywhere you want it , in Controller or Blade File
Now You should add this method to web.php or any route file to fire our operators
L::LangNonymous();
do you have admin panel and you want access route path to lang ? add this in route files if you want and set path like admin !!
L::Panel('admin');
now you are ready to see your route like this It is preferable to place these lines in the first line of the file
<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ L::Panel('admin'); L::LangNonymous();
okay You have to add this public middleware and you have Put all your routes inside this middelware
Route::group(['middleware'=>'Lang'],function(){ // put all routes here please ...i'ts fine :) });
now you maybe want configure your file langnonymous
<?php return [ 'UserModeLang'=>true, // true,false | if you want save lang in User Tbl Set true auto detected user lang 'LangRoute'=>'langnonymous', // Route Name You Can Change Route Name 'column_lang'=>'lang', // You May put The Defualt column if you are enable UserModeLang for true 'languages'=>['ar','en','es','jp'], // Put Your Language website Usage 'defaultLanguage'=>'ar', // Set Your Default Language (ar,en,es Any Short Lang From languages array) 'redirectAfterSet'=>'back', //Set Direction home,back | Back reflect to function back | home to index or other route ];
this is methods and classes built in package you can use all form any where
app('lang'); app('l'); // if you want methods !! okay that's was easy L::lang(); L::l(); // master session session('anonylang'); // you have a style directions !! don't worry // use this singletone in your file css or js :) whatever like example.com/css/style-rtl.css :) or rtl app('dir'); // RTL OR LTR L::dir(); // RTL or LTR //example.com/css/style-{{app('dir')}}.css from link tag //example.com/js/jquery-{{app('dir')}}.css from script tag // attention //if you are enable UserModeLang .. you should add column name to column_lang from user table in sql // you maybe make a new folders to usage this array 'languages'=>['ar','en','es','jp'] /* resource/lang/ar set file name and put this array <?php return [ 'ar'=>'العربية', 'en'=>'English', 'es'=>'Spanish', 'jp'=>'日本の', 'welcome'=>'مرحبا', ]; demo trans('yourfile.welcome') // مرحبا resource/lang/en set file name and put this array <?php return [ 'ar'=>'العربية', 'en'=>'English', 'es'=>'Spanish', 'jp'=>'日本の', 'welcome'=>'Welcome', ]; demo trans('yourfile.welcome') // welcome resource/lang/es set file name and put this array <?php return [ 'ar'=>'العربية', 'en'=>'English', 'es'=>'Spanish', 'jp'=>'日本の', 'welcome'=>'bienvenida', ]; demo trans('yourfile.welcome') // bienvenida resource/lang/jp set file name and put this array <?php return [ 'ar'=>'العربية', 'en'=>'English', 'es'=>'Spanish', 'jp'=>'日本の', 'welcome'=>'もしもし', ]; demo trans('yourfile.welcome') // もしもし or you can custom any language needed want */ // to set lang on your web okay follow this // in blade file put master language <a href="{{L::put('ar')}}">{{trans('yourfile.ar')}}</a> <a href="{{L::put('en')}}">{{trans('yourfile.en')}}</a> <a href="{{L::put('es')}}">{{trans('yourfile.es')}}</a> <a href="{{L::put('jp')}}">{{trans('yourfile.jp')}}</a> // or you can loop all automatically with method L::all(); @foreach(L::all() as $lang) <a href="{{L::put($lang)}}">{{trans('yourfile.'.$lang)}}</a> . @endforeach // for singleton
if you have any questions about this package join us on group facebook (https://www.facebook.com/groups/anonymouses.developers)
Enjoy :)
langnonymous/lang 适用场景与选型建议
langnonymous/lang 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.57k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2017 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「trans」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 langnonymous/lang 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 langnonymous/lang 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 langnonymous/lang 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
ZF3 module that glues Twig's {% trans %} and the standard translator together
Translation strings parser and web editor for Laravel applications
Database Base Translations Keys with Google Translations API Integration
Twig 3 translation extension
A PHP command-line utility and class library to convert source code between PHP 5.6 / 7.0 / 7.1 / 7.2.
Alfabank REST API integration
统计信息
- 总下载量: 3.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-14