Via Composer
$ composer require hokan22/laravel-translatorAdd the service provider to the providers array in config/app.php.
'providers' => [
Hokan22\LaravelTranslator\Provider\TranslatorProvider::class,
Hokan22\LaravelTranslator\Provider\TranslatorBladeProvider::class,
];Additionally you might want to add an alias to the aliases array within the config/app.php file.
'aliases' => [
'Translator' => Hokan22\LaravelTranslator\TranslatorFacade::class,
];You may want to use the middleware in order to control the global language setup inside app/Http/Kernel.php.
protected $routeMiddleware = [
'translator' => \Hokan22\LaravelTranslator\Middleware\TranslatorMiddleware::class,
];You can publish the configuration with:
php artisan vendor:publish --provider="Hokan22\LaravelTranslator\Provider\TranslatorProvider"This Package provides an easily extendable translation function with parameters for laravel.
After you registered the TranslatorBladeServiceProvider you can use the @t() or @translate() blade directives to translate your website into different languages.
You can define a locale through the translator middleware or define a locale for each translation individually.
@t('Hello World!')
@t('Hello {name}!', ['name' => World], 'de_DE')
@t('Hello World', [], 'fr_FR')
Parameters are simply surrounded by {} and their replacement provided as an array as the second parameter of the blade translate directive.
@t('Visit the site {link}.', ['link' => '<a href="example.com">Example.com</a>'])
If you use a different locale schema, just change the available_locales array in the config file.
To use your custom Translation Handler make sure it implements the Interface: Hokan22\LaravelTranslator\Handler\HandlerInterface.php
Now just change the 'handler' config parameter in config\translator.php to your custom Handler class.
'handler' => Hokan22\LaravelTranslator\Handler\DatabaseHandler::class,By default the Translator admin Interface is reachable under /translator/admin.
To override the default routes change the custom_routes parameter in the config to true and define the routes as you need them.
NOTE: In Order to use the "Live Mode" make sure you give the route to TranslatorAdminController@edit the name: 'translator.admin.edit'.
The MIT License (MIT). Please see License File for more information.