From 939a2042fb9c9e0064f2c78655dfe0a7f6c36634 Mon Sep 17 00:00:00 2001 From: Ahti Nurme Date: Fri, 2 Feb 2024 17:13:55 +0200 Subject: [PATCH] Should respect the locale JSON file structure set by Laravel --- src/TranslationsManager.php | 6 +++++- src/helpers.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/TranslationsManager.php b/src/TranslationsManager.php index c2d31f0..ad63580 100644 --- a/src/TranslationsManager.php +++ b/src/TranslationsManager.php @@ -116,7 +116,11 @@ public function export($download = false): void foreach ($phrasesTree as $locale => $groups) { foreach ($groups as $file => $phrases) { - $langPath = $download ? storage_path("app/translations/$locale/$file") : lang_path("$locale/$file"); + if ($file === "$locale.json") { + $langPath = $download ? storage_path("app/translations/$file") : lang_path("$file"); + } else { + $langPath = $download ? storage_path("app/translations/$locale/$file") : lang_path("$locale/$file"); + } if (! $this->filesystem->isDirectory(dirname($langPath))) { $this->filesystem->makeDirectory(dirname($langPath), 0755, true); diff --git a/src/helpers.php b/src/helpers.php index 5c24965..fecb59d 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -60,6 +60,10 @@ function buildPhrasesTree($phrases, $locale): array /** @var \Outhebox\TranslationsUI\Models\Phrase $phrase */ foreach ($phrases as $phrase) { + if ($phrase->file->file_name === "$locale.json") { + $tree[$locale][$phrase->file->file_name][$phrase->key] = ! blank($phrase->value) ? $phrase->value : $phrase->source->value; + continue; + } setArrayValue( array: $tree[$locale][$phrase->file->file_name], key: $phrase->key,