diff --git a/src/PackageServiceProvider.php b/src/PackageServiceProvider.php index 4b54c74..415e88e 100644 --- a/src/PackageServiceProvider.php +++ b/src/PackageServiceProvider.php @@ -42,6 +42,14 @@ public function boot() { $this->bootingPackage(); + if ($this->package->hasTranslations) { + $langPath = 'vendor/' . $this->package->shortName(); + + $langPath = (function_exists('lang_path')) + ? lang_path($langPath) + : resource_path('lang/' . $langPath); + } + if ($this->app->runningInConsole()) { foreach ($this->package->configFileNames as $configFileName) { $this->publishes([ @@ -71,13 +79,8 @@ public function boot() } if ($this->package->hasTranslations) { - // Laravel 8.64 and up uses lang_path(). - $path = (version_compare(app()->version(), "8.64") >= 0) - ? lang_path("vendor/{$this->package->shortName()}") - : resource_path("lang/vendor/{$this->package->shortName()}"); - $this->publishes([ - $this->package->basePath('/../resources/lang') => $path, + $this->package->basePath('/../resources/lang') => $langPath, ], "{$this->package->shortName()}-translations"); } @@ -99,7 +102,8 @@ public function boot() ); $this->loadJsonTranslationsFrom($this->package->basePath('/../resources/lang/')); - $this->loadJsonTranslationsFrom(resource_path('lang/vendor/'. $this->package->shortName())); + + $this->loadJsonTranslationsFrom($langPath); } if ($this->package->hasViews) { diff --git a/tests/PackageServiceProviderTests/PackageTranslationsTest.php b/tests/PackageServiceProviderTests/PackageTranslationsTest.php index 9035471..d99c74f 100644 --- a/tests/PackageServiceProviderTests/PackageTranslationsTest.php +++ b/tests/PackageServiceProviderTests/PackageTranslationsTest.php @@ -26,8 +26,7 @@ public function it_can_publish_the_translations() ->artisan('vendor:publish --tag=package-tools-translations') ->assertExitCode(0); - // Laravel 8.64 and up uses lang_path(). - $path = (version_compare(app()->version(), "8.64") >= 0) + $path = (function_exists('lang_path')) ? lang_path("vendor/package-tools/en/translations.php") : resource_path("lang/vendor/package-tools/en/translations.php");