Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.

Hokan22/laravel-translator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

105 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Translator

Latest Version on Packagist Software License Scrutinizer Code Quality

Install

Via Composer

$ composer require hokan22/laravel-translator

Setup

Add 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,
];

Middleware

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,
];

Publishing

You can publish the configuration with:

php artisan vendor:publish --provider="Hokan22\LaravelTranslator\Provider\TranslatorProvider"

Usage

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

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>'])

Custom Locales

If you use a different locale schema, just change the available_locales array in the config file.

Custom Translation Handler

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,

Custom Translation Routes

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'.

License

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors