Skip to content

Commit

Permalink
Merge pull request #52 from zupolgec/fix-lang-path
Browse files Browse the repository at this point in the history
Use lang_path() when available
  • Loading branch information
freekmurze authored Mar 15, 2022
2 parents c211839 + 9bd802b commit baeb3df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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");
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit baeb3df

Please sign in to comment.