Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix for Laravel 9+: support moved language resource path in Laravel 9 #166

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

Open
timvisee wants to merge 1 commit into rmariuzzo:master
base: master
Choose a base branch
Loading
from timvisee:master

Conversation

Copy link

@timvisee timvisee commented Feb 15, 2022
edited
Loading

Laravel 9 moves the language directory, breaking the current implementation.

This change uses app()->langPath() in Laravel 9+ to dynamically get the language resource path, as recommended per documentation.

This should support installations updated from 8 to 9 still using the old path.

przemekperon, Techworker, and lphilps reacted with thumbs up emoji
@timvisee timvisee changed the title (削除) Support moved language resource path in Laravel 9+ (削除ここまで) (追記) Fix for Laravel 9+: support moved language resource path in Laravel 9 (追記ここまで) Feb 15, 2022
Copy link

Any chance on merging this one? Without it the package doesn't work with default Laravel 9 install.

emaerka, Techworker, SamyMuhammad, and lphilps reacted with thumbs up emoji

Copy link

I have found an alternative way. Create a service provider which references the Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider and overwrite the register method. Then just add your own service provider to config/app.php and it will work with the new path.

ayoubaitouhmad reacted with thumbs up emoji

Copy link

ZejdCicak commented May 18, 2022
edited
Loading

@mirkoschmidt how would you reference another service provider form a service provider? Can you share your solution please?

Copy link

mirkoschmidt commented May 19, 2022
edited
Loading

Under app/Providers I created the following provider "LaravelLangJSServiceProvider" with the following content

<?php
namespace App\Providers;
use Mariuzzo\LaravelJsLocalization\Commands\LangJsCommand;
use Mariuzzo\LaravelJsLocalization\Generators\LangJsGenerator;
use Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider;
class LaravelLangJsServiceProvider extends LaravelJsLocalizationServiceProvider
{
 /**
 * Register the service provider.
 */
 public function register()
 {
 // Bind the Laravel JS Localization command into the app IOC.
 $this->app->singleton('localization.js', function ($app) {
 $app = $this->app;
 $laravelMajorVersion = (int) $app::VERSION;
 $files = $app['files'];
 if ($laravelMajorVersion === 4) {
 $langs = $app['path.base'].'/app/lang';
 } elseif ($laravelMajorVersion >= 5 && $laravelMajorVersion < 9) {
 $langs = $app['path.base'].'/resources/lang';
 } elseif ($laravelMajorVersion >= 9) {
 $langs = app()->langPath();;
 }
 $messages = $app['config']->get('localization-js.messages');
 $generator = new LangJsGenerator($files, $langs, $messages);
 return new LangJsCommand($generator);
 });
 // Bind the Laravel JS Localization command into Laravel Artisan.
 $this->commands('localization.js');
 }
}

and in config/app.php in the section "providers" i added this at the end

App\Providers\LaravelLangJsServiceProvider::class,

with reference i mean extends.

SamyMuhammad, renatoxm, mahmoud-ow, wilpat, ayoubaitouhmad, stylder, and fsasvari reacted with thumbs up emoji

Copy link

lphilps commented Jul 13, 2022

Any chance of getting this PR merged and another release generated? I just had to go the "override the service provider" route as detailed by @mirkoschmidt to get this to work in Laravel 9.

Copy link

When this can be merged please?

Copy link
Owner

Today, I'm gonna check that one. I will be careful with the versioning too.

nasirouwagana reacted with thumbs up emoji

Copy link

amadeann commented Dec 6, 2023

Until this is merged, this command works for default location of lang files in Laravel 9+:
php artisan lang:js --source lang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@rmariuzzo rmariuzzo rmariuzzo approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /