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

Wrong Lang directory for Laravel 11 #198

Open
stefanrakicfaxi opened this issue Dec 9, 2024 · 2 comments
Open

Wrong Lang directory for Laravel 11 #198

stefanrakicfaxi opened this issue Dec 9, 2024 · 2 comments

Comments

@stefanrakicfaxi
Copy link

In your LaravelJsLocalizationServiceProvider you have conditions:
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['path.base'].'/lang';
}

I use Laravel 11 and $laravelMajorVersion = 11, and when you are in this elseif ($laravelMajorVersion >= 5 && $laravelMajorVersion < 9) condition is true and try to read from wrong directory, please add condition >= 5 && < 9

@jonaszkadziela
Copy link

jonaszkadziela commented Dec 20, 2024

@stefanrakicfaxi I am facing the same problem in my Laravel 11 project. As a temporary solution, you can overwrite the service provider.

Create app/Providers/LaravelJsLocalizationServiceProvider.php with the following content:

<?php

namespace App\Providers;

use Mariuzzo\LaravelJsLocalization\Commands\LangJsCommand;
use Mariuzzo\LaravelJsLocalization\Generators\LangJsGenerator;
use Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider as BaseLaravelJsLocalizationServiceProvider;

class LaravelJsLocalizationServiceProvider extends BaseLaravelJsLocalizationServiceProvider
{
    /**
     * There is a problem in v1.11.1 of mariuzzo/laravel-js-localization package.
     * So, we overwrite the register method to use the correct path for language files.
     */
    public function register(): void
    {
        $this->app->singleton('localization.js', function () {
            $files = $this->app['files'];
            $langs = $this->app['path.base'] . '/lang';

            $messages = $this->app['config']->get('localization-js.messages');
            $generator = new LangJsGenerator($files, $langs, $messages);

            return new LangJsCommand($generator);
        });

        $this->commands('localization.js');
    }
}

And register it in bootstrap/providers.php:

<?php

return [
    App\Providers\AppServiceProvider::class,
    App\Providers\LaravelJsLocalizationServiceProvider::class,
];

@bhanwarpsrathore
Copy link

@stefanrakicfaxi @jonaszkadziela This is fixed in #192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants