Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Localization in Laravel 5.x

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 146
    Comment on it

    In Laravel 5.x we have lang class which will help us to retrieving string in different languages that will help us to easily support multiple languages.

    The folder structure for /resources/lang files are

    /resources
        /lang
            /en
                messages.php
           /es
               messages.php
    

    Example:

    Language files always give an array of keyed strings.

    <?php
    return array(
        'welcome' => 'Welcome to our application'
    );
    

    Note: we can also change our default language by changing in the app/config/app.php configuration file.

    App::setLocale('es');
    

    Configuring The Locale

    All the configuration of locale is stored in the config/app.php.We can also change the active language at runtime using the setLocale method on the App facade:

    Example:

    Route::get('welcome/{locale}', function ($locale) {
        App::setLocale($locale);
    
        //
    });
    

    By this way we can make our site multilingual.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: