Search code examples
phplaravellocale

Can I split up language files in Laravel to organize my locale file(s)?


I would really like to split up my messages.php locale file into more meaningfull files to get a better, more functional, organized set of language files. Is this in any way possible to achieve?

Thanks.


Solution

  • Yes you can, you only have to use the file name in the key of the message like this:

    /app
        /lang
            /en
                messages.php
                other.php
    

    In the "other.php" file:

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

    In your controller or in a blade template yo can get the locale string like this:

    echo Lang::get('other.welcome');
    

    Like the docs said:

    The first segment of the string passed to the get method is the name of the language file, and the second is the name of the line that should be retrieved.