2017 © Pedro Peláez
 

library translator

Flexible Laravel translator based on .CSV language files

image

webklex/translator

Flexible Laravel translator based on .CSV language files

  • Tuesday, April 25, 2017
  • by webklex
  • Repository
  • 1 Watchers
  • 1 Stars
  • 129 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

Translator (CSV File based)

Latest Version on Packagist ![Software License][ico-license] Build Status ![Total Downloads][ico-downloads], (*1)

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

Install

Via Composer, (*3)

``` bash $ composer require webklex/translator, (*4)


## Setup Add the service provider to the providers array in `config/app.php`. ``` 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., (*5)

``` php protected $routeMiddleware = [ 'translator' => Webklex\Translator\Middleware\TranslatorMiddleware::class, ];, (*6)


## 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: ``` php /** * 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: ``` php Route::get('/language/{locale}', 'YourControllerName@changeLanguage');, (*7)


## Publishing You can publish everything at once ``` php php artisan vendor:publish --provider="Webklex\Translator\Providers\TranslatorServiceProvider"

or you can publish groups individually., (*8)

``` php php artisan vendor:publish --provider="Webklex\Translator\Providers\TranslatorServiceProvider" --tag="config", (*9)


## 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. ``` php 'aliases' => [ 'Lang' => Webklex\Translator\Facades\TranslatorFacade::class ];

You registered the TranslatorBladeServiceProvider you can even use this easy shorthand directive., (*10)

``` html @t('My translation') @t('My translation', 'en'), (*11)


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`. ``` 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., (*12)

Testing

bash $ composer test, (*13)

Security

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

Credits

License

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

The Versions

25/04 2017

dev-master

9999999-dev https://github.com/webklex/translator

Flexible Laravel translator based on .CSV language files

  Sources   Download

MIT

The Requires

 

The Development Requires

by Malte Goldenbaum

laravel csv language translator multilang webklex

25/04 2017

1.0.5.1

1.0.5.1 https://github.com/webklex/translator

Flexible Laravel translator based on .CSV language files

  Sources   Download

MIT

The Requires

 

The Development Requires

by Malte Goldenbaum

laravel csv language translator multilang webklex

15/04 2017

1.0.5.0

1.0.5.0 https://github.com/webklex/translator

Flexible Laravel translator based on .CSV language files

  Sources   Download

MIT

The Requires

 

The Development Requires

by Malte Goldenbaum

laravel csv language translator multilang webklex

19/03 2017

1.0.4.2

1.0.4.2 https://github.com/webklex/translator

Flexible Laravel translator based on .CSV language files

  Sources   Download

MIT

The Requires

 

The Development Requires

by Malte Goldenbaum

laravel csv language translator multilang webklex

15/03 2017

1.0.4.1

1.0.4.1 https://github.com/webklex/translator

Flexible Laravel translator based on .CSV language files

  Sources   Download

MIT

The Requires

 

The Development Requires

by Malte Goldenbaum

laravel csv language translator multilang webklex