Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lang_path() when available #52

Merged
merged 1 commit into from Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/PackageServiceProvider.php
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
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