Mal eben nachgeschaut und nein, bei JSON wird kein Nested unterstützt
.
Ich habe eine Lösung gefunden die auch wunderbar mit nested arbeitet. Poste sobald ich etwas Zeit finde die Lösung für Laravel 11
Lösung für Laravel Lang JSON nested Files:
1) Erstelle eine Translator Klasse unter app/Translation/Translator.php
Folgender Inhalt für Translator.php
PHP
<?php
namespace App\Translation;
use Illuminate\Support\Arr;
use Illuminate\Translation\Translator as BaseTranslator;
class Translator extends BaseTranslator
{
/**
* @param $key
* @param array $replace
* @param $locale
* @param $fallback
*
* @return array|string|null
*/
public function get($key, array $replace = [], $locale = null, $fallback = true)
{
$results = parent::get($key, $replace, $locale, $fallback);
// If the key does not contain nested translation
// or the result did not return the key back, then it's okay
if (!str_contains($key, '.') || $results !== $key) {
if (is_array($results)) {
return $key;
}
return $results;
}
$locale = $locale ?: $this->locale;
$line = Arr::get($this->loaded['*']['*'][$locale], $key);
// Handle fallback to default language
if (!isset($line) && $fallback && !empty($this->getFallback()) && $locale !== $this->getFallback()) {
$this->load('*', '*', $this->getFallback());
$line = Arr::get($this->loaded['*']['*'][$this->getFallback()], $key);
}
return $this->makeReplacements($line ?: $key, $replace);
}
}
Alles anzeigen
2) Hänge die Klasse in app/Providers/AppServiceProvider.php an
Folgender Inhalt für AppServiceProvider.php
Jetzt kannst du mit
oder
deine Übersetzungen in deiner Laravel App abrufen. Beachte das du deine Lang Files nun zb als de.json speicherst.