Get whole language file array
Lets say, a language file: lang/en/countries.php
return [
'afg' => 'Afghanistan',
'ala' => 'Aland',
'alb' => 'Albania',
'dza' => 'Algeria',
'asm' => 'American Samoa'
];
Retrieving lines from the language file with Lang::get() method
$array = Lang::get('countries'); // return entire array
$text = Lang::get('countries.afg'); // return single item
for Laravel 5.0 & above, You may also use the trans helper function, which is an alias for the Lang::get() method.
$array = trans('countries'); // return entire array
$text = trans('countries.afg'); // return single item
Find out more on Laravel docs...
You can get the entire array with Lang::get()
.
$array = Lang::get('pagination'); // return entire array
$text = Lang::get('pagination.next'); // return single item
Here's how yo can load them:
Route::get('test', function()
{
$a = File::getRequire(base_path().'/app/lang/en/pagination.php');
foreach($a as $key => $value)
{
echo "$key => $value<br>";
}
});
If you need to load them all, you can use:
$languages = File::directories(base_path().'/app/lang/');
I had to find a way to create an language import command in my Glottos package: https://github.com/antonioribeiro/glottos.