From 624d8df5aefc725a7226af086aab1ab39d7b8d25 Mon Sep 17 00:00:00 2001 From: Amir Rami Date: Wed, 23 Feb 2022 16:16:33 +0100 Subject: [PATCH] New lang path for Laravel 9.x (#33) --- composer.json | 5 ++++- src/Services/Collectors/DefaultKeyCollector.php | 6 +++--- src/Services/Collectors/JsonKeyCollector.php | 2 +- src/Services/Writers/DefaultWriter.php | 2 +- src/Services/Writers/JsonWriter.php | 2 +- src/helpers.php | 12 ++++++++++++ tests/Concerns/CreatesTestFiles.php | 8 ++++---- tests/Concerns/ImportsLangFiles.php | 2 +- tests/TestCase.php | 2 +- 9 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 src/helpers.php diff --git a/composer.json b/composer.json index d6bd9f9..ac6b5c4 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,10 @@ "autoload": { "psr-4": { "Amirami\\Localizator\\": "src" - } + }, + "files": [ + "src/helpers.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/Services/Collectors/DefaultKeyCollector.php b/src/Services/Collectors/DefaultKeyCollector.php index cc3db8c..f675d2d 100644 --- a/src/Services/Collectors/DefaultKeyCollector.php +++ b/src/Services/Collectors/DefaultKeyCollector.php @@ -36,7 +36,7 @@ public function getTranslated(string $locale): Collection */ protected function getFiles(string $locale): Collection { - $dir = resource_path('lang'.DIRECTORY_SEPARATOR.$locale); + $dir = lang_path($locale); if (! file_exists($dir)) { if (! mkdir($dir, 0755) && ! is_dir($dir)) { @@ -59,8 +59,8 @@ protected function getFiles(string $locale): Collection */ protected function requireFile(string $locale, SplFileInfo $fileInfo): array { - return require resource_path( - 'lang'.DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.$fileInfo->getRelativePathname() + return require lang_path( + $locale.DIRECTORY_SEPARATOR.$fileInfo->getRelativePathname() ); } } diff --git a/src/Services/Collectors/JsonKeyCollector.php b/src/Services/Collectors/JsonKeyCollector.php index 2f913e3..0c8a3a7 100644 --- a/src/Services/Collectors/JsonKeyCollector.php +++ b/src/Services/Collectors/JsonKeyCollector.php @@ -14,7 +14,7 @@ class JsonKeyCollector implements Collectable */ public function getTranslated(string $locale): Collection { - $file = resource_path('lang'.DIRECTORY_SEPARATOR."{$locale}.json"); + $file = lang_path("{$locale}.json"); if (! file_exists($file)) { return new JsonKeyCollection; diff --git a/src/Services/Writers/DefaultWriter.php b/src/Services/Writers/DefaultWriter.php index 95b038f..61863f6 100644 --- a/src/Services/Writers/DefaultWriter.php +++ b/src/Services/Writers/DefaultWriter.php @@ -73,6 +73,6 @@ protected function exportArray(array $contents): string */ protected function getFile(string $locale, string $fileName): string { - return resource_path('lang'.DIRECTORY_SEPARATOR.$locale.DIRECTORY_SEPARATOR.$fileName.'.php'); + return lang_path($locale.DIRECTORY_SEPARATOR.$fileName.'.php'); } } diff --git a/src/Services/Writers/JsonWriter.php b/src/Services/Writers/JsonWriter.php index e7930c2..1f5ca4c 100644 --- a/src/Services/Writers/JsonWriter.php +++ b/src/Services/Writers/JsonWriter.php @@ -14,7 +14,7 @@ class JsonWriter implements Writable */ public function put(string $locale, Translatable $keys): void { - $file = resource_path('lang'.DIRECTORY_SEPARATOR."{$locale}.json"); + $file = lang_path("{$locale}.json"); (new Filesystem)->put( $file, diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 0000000..28221d7 --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,12 @@ +createTestFile( - $contents, - 'lang'.DIRECTORY_SEPARATOR.$fileName + file_put_contents( + lang_path($fileName), + $contents ); } @@ -67,7 +67,7 @@ protected function createTestJsonLangFile(array $contents, string $locale): void protected function createTestDefaultLangFile(array $contents, string $fileName, string $locale): void { $export = sprintf("