I have a Service Provider in laravel
which reads all available languages from locale
and save them in a Cache file. Everything works fine, but all translations are in German. I expect to get them in language de
and en
. This is the code from the ServiceProvider
:
$minutes = 24*60;
Cache::remember('translations', $minutes, function () {
$directories = array('de','en');
$collection = new \stdClass;
foreach($directories as $directory)
{
$path = resource_path('lang/' .$directory);
$allTranslations = collect(File::allFiles($path))->flatMap(function ($file,$directory) {
return [
($translation = $file->getBasename('.php')) => trans($translation,array(),null,$directory),
];
});
$allModuleTranslations = collect(File::allFiles($path .'/modul'))->flatMap(function ($file,$directory) {
return [
($translation = $file->getBasename('.php')) => trans('modul/' .$translation,array(),null,$directory),
];
});
$collection->$directory = $allTranslations->merge($allModuleTranslations);
}
return json_encode($collection);
Can anybody see, why it returns all words in German?
The result looks like this:
{
de:
auth:
failed: "Diese Zugangsdaten wurden nicht in unserer Datenbank gefunden."
throttle: "Zu viele Login Versuche. Versuchen Sie es bitte in :seconds Sekunden."
en:
auth:
failed: "Diese Zugangsdaten wurden nicht in unserer Datenbank gefunden."
throttle: "Zu viele Login Versuche. Versuchen Sie es bitte in :seconds Sekunden."
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire