承接 webklex/translator 相关项目开发

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

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

webklex/translator

Composer 安装命令:

composer require webklex/translator

包简介

Flexible Laravel translator based on .CSV language files

README 文档

README

Latest Version on Packagist Software License Build Status Total Downloads

This is a translator package provides everything you need to get started with a quiet fast CSV file based translation service.

Install

Via Composer

$ composer require webklex/translator

Setup

Add the service provider to the providers array in config/app.php.

'providers' => [
    Webklex\Translator\Providers\TranslatorServiceProvider::class,
    Webklex\Translator\Providers\TranslatorBladeServiceProvider::class,
];

Middleware

You may want to use the middleware in order to control the global language setup inside app/Http/Kernel.php.

protected $routeMiddleware = [
    'translator' => Webklex\Translator\Middleware\TranslatorMiddleware::class,
];

Routes and language switching

If you want to change the system language by clicking on a link, you could use something like this:

Inside your controller:

/**
 * Change the current language
 *
 * @param string $locale
 * @return \Illuminate\Http\RedirectResponse
 */
public function changeLanguage($locale){
    if(in_array($locale, config('translator.available'))){
        Session::put('locale', $locale);
        Session::save();
        app()->setLocale($locale);
    }

    return redirect()->back();
}

Inside your routing file:

Route::get('/language/{locale}', 'YourControllerName@changeLanguage');

Publishing

You can publish everything at once

php artisan vendor:publish --provider="Webklex\Translator\Providers\TranslatorServiceProvider"

or you can publish groups individually.

php artisan vendor:publish --provider="Webklex\Translator\Providers\TranslatorServiceProvider" --tag="config"

Usage

This is a translator package provides everything you need to get started with a quiet fast CSV file based translation service. Your translation files will be stored by default in resources/lang/ your language code (e.g. en) /default.csv.

Access Translator by its Facade (Webklex\Translator\Facades\TranslatorFacade). Therefor you might want to add an alias to the aliases array within the config/app.php file.

'aliases' => [
    'Lang' => Webklex\Translator\Facades\TranslatorFacade::class
];

You registered the TranslatorBladeServiceProvider you can even use this easy shorthand directive.

@t('My translation')
@t('My translation', 'en')

If you are using something like my other package webklex/helpers you can use a helper function to make the access even easier.

Therefor create a new helper: php artisan make:helper translator and edit the app/Helpers/translator.php.

if (!function_exists('_t')) {

    /**
     * Shorthand translation
     * @param string $string
     * @param string $locale
     *
     * @return string
     */
    function _t($string, $locale = null)
    {
        return Webklex\Translator\Facades\TranslatorFacade::get($string, $locale);
    }
}

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email github@webklex.com instead of using the issue tracker.

Credits

License

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

统计信息

  • 总下载量: 274
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固