Giter Club home page Giter Club logo

Comments (7)

ivanvermeyen avatar ivanvermeyen commented on June 12, 2024 1

Hello,

A PR is always welcome.

When I was looking through my code for your question, I actually just discovered the bug with hasCustomDomains() that you fixed above. The same is true for hasCustomSlugs().

The whole scoped config feature needs more testing and probably needs to be tweaked here and there.
It would be nice if it could work fluently with the main config.
But that is more complex than it seams I think.

One problem you should double check is if your routes have duplicate names, because you use duplicate locales.

I can give this some deeper thought later today.

from laravel-localized-routes.

cdo9 avatar cdo9 commented on June 12, 2024

I added a $locales parameter to the LocaleConfig::hasCustomDomains() function and the LocaleConfig::getSupportedLocales().

Here are the updated functions :

    public function hasCustomDomains($locales = null): bool
    {
        $firstValue = array_values($this->getSupportedLocales($locales))[0] ?? '';
        $containsDot =  strpos($firstValue, '.') !== false;

        return $containsDot;
    }
    public function getSupportedLocales($locales = null): array
    {
        return $locales ?: $this->supportedLocales;
    }

Updated the register function line 28 : $usingDomains = LocaleConfig::hasCustomDomains($locales);

And for now, I can access all my urls from my table above. Do you think I might have broken something ? I will keep testing and give you updates accordingly.

from laravel-localized-routes.

cdo9 avatar cdo9 commented on June 12, 2024

Thanks for your reply, I will continue working on this in the next days/weeks :)

I am now trying to have this urls working :

url locale
firstwebsite.test/en/category/{translatedSlug} en
firstwebsite.test/fr/categorie/{translatedSlug} fr
firstwebsite.test/pt/categoria/{translatedSlug} pt
secondwebsite.test/category/{translatedSlug} en
deuxiemesite.test/categorie/{translatedSlug} fr
segundosite.test/categoria/{translatedSlug} pt

I added this two routes to my web.php file :

Route::get(Lang::uri('firstwebsite/shop/category/{$productCategory}'),
[\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('firstwebsite.shop.category');
Route::get(Lang::uri('secondwebsite/shop/category/{$productCategory}'),
[\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('secondwebsite.shop.category');

Translation is working well, I have done a foreach of my categories and urls are ok but I have a 404 when accessing my URLs, I need to figure out why this is happening

EDIT 1 :

When I was looking through my code for your question, I actually just discovered the bug with hasCustomDomains() that you fixed above. The same is true for hasCustomSlugs().

Yes you are right for hasCustomSlugs. Will update this has well.

One problem you should double check is if your routes have duplicate names, because you use duplicate locales.

I think with my route naming i am ok ? firstwebsite.shop.category & secondwebsite.shop.category

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on June 12, 2024

Could you show me a more complete example of your route registration?
And perhaps a screenshot of the php artisan route:list command?
Trying to understand the flow of your routes.

from laravel-localized-routes.

cdo9 avatar cdo9 commented on June 12, 2024

EDIT : my bad... i removed the $ sign and everything is working well!! Here are the example :

web.php

    Route::domain('firstwebsite.test')->group(function () {
        Route::localized(function () {
        // Home
        Route::get('/', [\App\Http\Controllers\HomeController::class, 'index'])->name('firstwebsite.home');
        // Shop
        Route::get(Lang::uri('firstwebsite/shop/category/{productCategory}'), [\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('firstwebsite.shop.category');
        }, ['supported_locales' => ['en', 'fr', 'pt']]
        );
    });

    Route::pattern('secondwebsite', 'secondwebsite.test|deuxiemesite.test|segundosite.test');
    Route::domain('{secondwebsite}')->group(function () {
        Route::localized(function () {
            // Home
            Route::get('/', [\App\Http\Controllers\HomeController::class, 'index'])->name('secondwebsite.home');
            // Shop
            Route::get(Lang::uri('secondwebsite/shop/category/{productCategory}'), [\App\Http\Controllers\Shop\CategoryController::class, 'show'])->name('secondwebsite.shop.category');
        }, ['supported_locales' => ['en' => 'secondwebsite.test', 'fr' => 'deuxiemesite.test', 'pt' => 'segundosite.test']]
        );
    });

php artisan route:list

GET|HEAD   secondwebsite.test/ en.secondwebsite.home › HomeController@index
GET|HEAD   deuxiemesite.test/ fr.secondwebsite.home › HomeController@index
GET|HEAD   segundosite.test/ pt.secondwebsite.home › HomeController@index
GET|HEAD   segundosite.test/categoria/{productCategory} pt.secondwebsite.shop.category › Shop\CategoryController@show
GET|HEAD   deuxiemesite.test/categorie/{productCategory} fr.secondwebsite.shop.category › Shop\CategoryController@show
GET|HEAD   secondwebsite.test/category/{productCategory} en.secondwebsite.shop.category › Shop\CategoryController@show
GET|HEAD   firstwebsite.test/en en.firstwebsite.home › HomeController@index
GET|HEAD   firstwebsite.test/en/category/{productCategory} en.firstwebsite.shop.category › Shop\CategoryController@show
GET|HEAD   firstwebsite.test/fr fr.firstwebsite.home › HomeController@index
GET|HEAD   firstwebsite.test/fr/categorie/{productCategory} fr.firstwebsite.shop.category › Shop\CategoryController@show
GET|HEAD   firstwebsite.test/pt pt.firstwebsite.home › HomeController@index
GET|HEAD   firstwebsite.test/pt/categoria/{productCategory} pt.firstwebsite.shop.category › Shop\CategoryController@show

from laravel-localized-routes.

cdo9 avatar cdo9 commented on June 12, 2024

Hello @ivanvermeyen

I was waiting Laravel 11 to start this new website, so I will update this issue according to my finds.

There is an error on the README for Laravel 11 configuration : Target class [CodeZero\Localizer\Middleware\SetLocale] does not exist.
The class is : \CodeZero\LocalizedRoutes\Middleware\SetLocale::class,

from laravel-localized-routes.

ivanvermeyen avatar ivanvermeyen commented on June 12, 2024

Woops, that's what I get for copy-pasting :)
Fixed it now.
Thanks for catching that!

from laravel-localized-routes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.