chinleung / laravel-multilingual-routes

A package to handle multilingual routes in your Laravel application.
https://github.com/chinleung/laravel-multilingual-routes-demo
MIT License
395 stars 25 forks source link

Customize default locale for urls #14

Closed jsanchezgr closed 4 years ago

jsanchezgr commented 4 years ago

Context

I have a site with the following locales: es (default), en (generic) and pt. The url structure should be as follows:

/nosotros //es
/en/about-us //en
/pt/sobre-nos //pt

That can be achieved by setting app.fallback_locale = 'es', however I need english to be the generic language.

Problem

Taking a look to the code, this function forces the default (hidden) url prefix, to be the same as the fallback_locale language.

protected function generatePrefixForLocale(string $key, string $locale) : ?string
    {
        if ($key == '/') {
            return null;
        }

        if ($locale != config('app.fallback_locale')) {
            return $locale;
        }

        return config('laravel-multilingual-routes.prefix_fallback')
            ? $locale
            : null;
    }

Potential fix

Just by adding a laravel-multilingual-routes.default_locale config param should do the trick. If you're happy with that, I can provide a PR.

Thanks

chinleung commented 4 years ago

@jsanchezgr Yeah sure I'd accept a PR for that. Might as well change the prefix_fallback to prefix_default. 😄

chinleung commented 4 years ago

@jsanchezgr I will have time to fix this issue this weekend. Can you let me know if you are about to finish this? Don't want to waste your effort! 😅

jsanchezgr commented 4 years ago

Go ahead! I barely started it. Thanks

chinleung commented 4 years ago

@jsanchezgr The configuration is now available in v1.4.0. 😄