Skip to content

Commit

Permalink
Nested-folders-support (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: 2btech.dev2 <2btech.dev2@gmail.com>
  • Loading branch information
kha333n and 2btechdev2 authored Apr 20, 2024
1 parent 6766aa6 commit fb41286
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Actions/SyncPhrasesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public static function execute(Translation $source, $key, $value, $locale, $file
]);

$isRoot = $file === $locale.'.json' || $file === $locale.'.php';
$extension = pathinfo($file, PATHINFO_EXTENSION);
$filePath = str_replace('.'.$extension, '', str_replace($locale.DIRECTORY_SEPARATOR, '', $file));

$translationFile = TranslationFile::firstOrCreate([
'name' => pathinfo($file, PATHINFO_FILENAME),
'extension' => pathinfo($file, PATHINFO_EXTENSION),
'name' => $filePath,
'extension' => $extension,
'is_root' => $isRoot,
]);

Expand Down
9 changes: 6 additions & 3 deletions src/TranslationsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Outhebox\TranslationsUI\Models\Translation;
use Symfony\Component\Finder\SplFileInfo;
use ZipArchive;

class TranslationsManager
Expand Down Expand Up @@ -67,8 +68,11 @@ public function getTranslations(string $locale): array
}

collect($files)
->map(function ($file) use ($locale) {
return $locale.DIRECTORY_SEPARATOR.$file->getFilename();
->map(function (SplFileInfo $file) use ($locale) {
if ($file->getRelativePath() === '') {
return $locale.DIRECTORY_SEPARATOR.$file->getFilename();
}
return $locale.DIRECTORY_SEPARATOR.$file->getRelativePath().DIRECTORY_SEPARATOR.$file->getFilename();
})
->when($this->filesystem->exists(lang_path($rootFileName)), function ($collection) use ($rootFileName) {
return $collection->prepend($rootFileName);
Expand Down Expand Up @@ -103,7 +107,6 @@ public function getTranslations(string $locale): array
$translations[$file] = [];
}
});

return $translations;
}

Expand Down

0 comments on commit fb41286

Please sign in to comment.