Skip to content

Commit

Permalink
Add version check for lang_path helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Voicecode B.V committed Feb 22, 2022
1 parent 1be0f3a commit 9aa990a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/PackageServiceProvider.php
Expand Up @@ -65,8 +65,13 @@ 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') => lang_path("vendor/{$this->package->shortName()}"),
$this->package->basePath('/../resources/lang') => $path,
], "{$this->package->shortName()}-translations");
}

Expand Down
Expand Up @@ -25,7 +25,12 @@ public function it_can_publish_the_translations()
$this
->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)
? lang_path("vendor/package-tools/en/translations.php")
: resource_path("lang/vendor/package-tools/en/translations.php");

$this->assertFileExists(lang_path('vendor/package-tools/en/translations.php'));
$this->assertFileExists($path);
}
}

2 comments on commit 9aa990a

@zupolgec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this change be applied also to the loadJsonTranslationsFrom function calls below?
Can I go ahead with the PR? @freekmurze
Also wouldn't be better to check for lang_path existence rather than Laravel version?
Thanks

@freekmurze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this change be applied also to the loadJsonTranslationsFrom function calls below?

Yup, if you want, you can send a PR for that.

Also wouldn't be better to check for lang_path existence rather than Laravel version?

That might be a bit better too, feel free to address it in the same PR.

Please sign in to comment.