Skip to content

deployteam/laravel-polytranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel PolyTranslate

Latest Version on Packagist Software License Total Downloads Build Status

Install

Require this package with composer using the following command:

composer require deployteam/laravel-polytranslate

After updating composer, add the service provider to the providers array in config/app.php

DeployTeam\PolyTranslate\ServiceProvider::class,

If you want to use the facade, add this to your facades in app.php:

'PolyTranslate' => DeployTeam\PolyTranslate\Facade::class,

>= Laravel 5.5 uses Package Auto-Discovery, so it's not required to manually add the ServiceProvider and the Facade.

Usage

Using PolyTranslate you can add multiple paths for language loading:

PolyTranslate::addPath(['themes/base/lang', 'themes/child/lang']); // without namespace
PolyTranslate::addNamespace('theme', ['themes/base/lang', 'themes/child/lang']); // with namespace

Laravel will start searching the directories for languages, and will merge anything it finds.

// themes/base/lang/en/header.php
return [
    'greetings' => 'Hello',
    'login' => 'Login'
];
// themes/child/lang/en/header.php
return [
    'login' => 'Authenticate',
    'register' => 'Register'
];

The final result will be:

[
    'greetings' => 'Hello',
    'login' => 'Authenticate',
    'register' => 'Register'
]

To use the translation, you just use the built-in Laravel functionality:

@lang('header.greetings') <!-- Without namespace -->
@lang('theme::header.greetings') <!-- With namespaces -->

License

The Laravel PolyTranslate is open-sourced software licensed under the MIT license

About

Add support for multiple localization paths

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages