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

Fix location of lang files to prevent applications with localization from breaking #10

Open
michaelklopf opened this issue Jan 26, 2024 · 1 comment · May be fixed by #9
Open

Fix location of lang files to prevent applications with localization from breaking #10

michaelklopf opened this issue Jan 26, 2024 · 1 comment · May be fixed by #9
Assignees

Comments

@michaelklopf
Copy link

I opened a PR that fixes an error, in which the translation helper can't find the translations anymore.

The app creates files in the pre Laravel 9 lang folder location. Laravel checks for that place and changes the lang path where the translations are searched for. This shouldn't happen though as Laravel 9s way is the new default.

See the PR for more information.

@dominik-eller
Copy link

dominik-eller commented Nov 20, 2024

Please accept that PR

For a workaround I made my own Serviceprovider to fix that and registered it in config/app.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Nova;

class NovaGoogleAutocompleteFixServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        // Determine the correct language path
        $langPath = $this->getLangPath();

        // Ensure translations are loaded correctly for the vendor package
        $this->loadTranslationsFrom($langPath . '/vendor/nova-google-autocomplete', 'nova-google-autocomplete');
        $this->loadJsonTranslationsFrom($langPath . '/vendor/nova-google-autocomplete');

        // Optionally re-register Nova translations for this package
        Nova::serving(function () use ($langPath) {
            Nova::translations($langPath . '/vendor/nova-google-autocomplete/' . app()->getLocale() . '.json');
        });
    }

    protected function getLangPath(): string
    {
        // Check if the `/lang` directory exists to determine the correct path
        return is_dir(base_path('lang')) ? base_path('lang') : resource_path('lang');
    }
}

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