Package Data | |
---|---|
Maintainer Username: | webklex |
Maintainer Contact: | github@webklex.com (Malte Goldenbaum) |
Package Create Date: | 2016-09-24 |
Package Last Update: | 2017-04-25 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 15:02:04 |
Package Statistics | |
---|---|
Total Downloads: | 269 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This is a translator package provides everything you need to get started with a quiet fast CSV file based translation service.
Via Composer
$ composer require webklex/translator
Add the service provider to the providers array in config/app.php
.
'providers' => [
Webklex\Translator\Providers\TranslatorServiceProvider::class,
Webklex\Translator\Providers\TranslatorBladeServiceProvider::class,
];
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,
];
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');
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"
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);
}
}
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email github@webklex.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.