Translate in a specific language in Laravel

There are 3 ways to achieve this:

  1. You can change default language at runtime by doing this:

App::setLocale('fr'); NB: This is not suitable for your current need as it will only take effect on next page load.

  1. You can set default language here app/config/app.php

'fallback_locale' => 'fr'

  1. I took a deeper look at Illuminate\Translation\Translator:

    get($key, array $replace = array(), $locale = null)

    This means you can do this using Translator Facade:

    Lang::get($key, array $replace = array(), $locale = null);

    Example:

    Lang::get('group.key',[],'fr');

NB: You folder structure should look like this

/app
    /lang
        /en
            messages.php
        /fr
            messages.php

To get a language specific translation - different from the current locales without setting and unsetting the locales, just do

__('description_1', [], 'en')

Tags:

Php

Laravel