Looking to hire Laravel developers? Try LaraJobs

laravel-polytranslate maintained by deployteam

Description
Add multiple locations for Laravel localization namespace
Author
Last update
2022/09/05 20:03 (dev-master)
License
Downloads
13
Tags

Comments
comments powered by Disqus

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