Laravel - Localization - __() instead of trans() helper function.

In Laravel you can retrieve lines from language files using the trans() helper function.

To keep our code simple we would like the __() helper function instead.

Create a new file: 'app/Support/Helpers.php'.

<?php
if ( ! function_exists('__')) {
    function __($string)
    {
        $r = trans('messages.' . $string);
        return (substr($r, 0, 9) === 'messages.' ? $string : $r);
    }
}

In order to load this file with autoloader we need to edit 'composer.json':

"autoload": {
    "files": [
        "app/Support/Helpers.php"
    ]
},

Finnaly we need to regenerate ( 'vender\composer\autoload_classmap.php') the list of all classes that need to be included:

composer dump-autoload