2017 © Pedro Peláez
 

library langman

Manage translations in Laravel App

image

kalamsoft/langman

Manage translations in Laravel App

  • Tuesday, March 20, 2018
  • by itz_decipher
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 40 % Grown

The README.md

Langman

Manage translations in Laravel App, (*1)

Langman is used to manage your translation using web. You can add new translation or edit the translation phrases or delete the translation of your Laravel App., (*2)

Langman

Installation

To get the latest version of Currency simply require it in your composer.json file., (*3)

"kalamsoft/langman": "1.0.*-dev"

or simply from console, (*4)

composer require kalamsoft/langman

Once Langman is installed you need to register the service provider with the application. Open up config/app.php and find the providers key., (*5)

'providers' => [
    Kalamsoft\Langman\LangServiceProvider::class,
]

Langman also ships with a facade which provides the static functions for manage translations. You can register the facade in the aliases key of your config/app.php file., (*6)

'aliases' => [

    'Langman' => Kalamsoft\Langman\Langman::class,

]

and publish using --tag=translation, (*7)

  php artisan vendor:publish --tag=translation

This will publish the following, (*8)

  • translation view files under resources/views/translation
  • config.json under resources/lang/en/
  • translation.php under config path

config.json is must to manage your translation which was used to manage all your translations., (*9)

Note: vendor:publish --tag=translation was must to generate config.json file!, (*10)

You need to create one middleware which is used to maintain the language across the Laravel App., (*11)

php artisan make:middleware Language

and use the following code inside the handle function, (*12)

        //thanks to -> https://mydnic.be/post/laravel-5-and-his-fcking-non-persistent-app-setlocale for non persistent locale problem
        if (\Session::has('locale')) {
            \App::setLocale(\Session::get('locale'));
        }
        else {
            // This is optional as Laravel will automatically set the fallback language if there is none specified
            \App::setLocale(\Config::get('app.fallback_locale'));
        }
        return $next($request);

and then register the middleware in kernel.php after the \Illuminate\Session\Middleware\StartSession::class,, (*13)

\App\Http\Middleware\Language::class,

this will holds the chosen language across the app., (*14)

How to use?

Rendering Available Translations

By default Langman uses the bootstrap css framework for managing translations. If you want to customize you can find the view files under resources\view\translation., (*15)

If you want to render available translations in your app, (*16)

{!! Langman::TranslationSwitch() !!}

It will render the following, (*17)

<li class="dropdown">
    <a href="#" data-toggle="dropdown" role="button" aria-expanded="true" class="dropdown-toggle">FR<span class="caret"></span></a> 
    <ul role="menu" class="dropdown-menu">
        <li><a href="url('lang/en')"> English</a></li>
        <li><a href="url('translation')">Manage Translation</a></li>
    </ul>
</li>    

So you can add this in header nav to change the translation if you want!, (*18)

Manage Translations

If you want to manage all your translations, navigate to translation in your app., (*19)

There you can add, edit or delete the translation., (*20)

By default you cannot the edit or remove the en., (*21)

translation routes are being protected with auth middleware., (*22)

Change Log

v.1 20-03-2018, (*23)

The Versions

20/03 2018

dev-master

9999999-dev

Manage translations in Laravel App

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

by Prabakaran T

language translation locale