schmittjoh / JMSI18nRoutingBundle

Allows you to internationalize your routing
http://jmsyst.com/bundles/JMSI18nRoutingBundle
358 stars 159 forks source link

Request::getLocale always returns default_locale #130

Open simohammedhttp opened 10 years ago

simohammedhttp commented 10 years ago

Hi,

The JMSI18nRoutingBundle works perfectly for the majority of my routes.

jms_i18n_routing: default_locale: fr locales: [fr, ar, en] strategy: prefix_except_default

But I had some issues with this route:

@Route("/{articlePath}", requirements={"articlePath"=".+"}) showAction($articlePath, Request $request)

@Route Is intended to match routes like category/subCategory/../articleSlug

$request->getLocale() always returns fr, inside the controller for these URLs:

/en/.. /ar/.. /fr/.. /.. (fr omitted)

And the route /fr/.. must not be matched according to the intended behaviour with the prefix_except_default strategy.

tks,

svperfecta commented 9 years ago

We're seeing this too.

ceesvanegmond commented 6 years ago

We're having the same problem. Is there an solution?

aik099 commented 6 years ago

Since we're all developers here somebody might as well go and looking into final routes built by the library to discover the problem 😉 . No real need to wait for 3 years to create a solution.

acasademont commented 6 years ago

Hi all! Happy to review any PRs, it shouldn't be too difficult to solve

aik099 commented 6 years ago

While looking at the library I've found out, that it takes all your routes prior to their dumping in compiled router and modifies them according to the strategy. This info should help to anyone looking at solving this problem.

simohammedhttp commented 6 years ago

I solved this a long time ago with a workaround, I mean the issue must be fixed at the bundle level for a reliable/sustainable solution.

I tweaked the @route.

@Route("{_locale}{articlePath}", requirements={"_locale"="en|ar|", "articlePath"=".+"})

.. time flies ... 3 years :o

ceesvanegmond commented 6 years ago

@simohammedhttp Yeah, that's basically not the fix I guess. Looking in to the library right now to fix it, but I don't know exactly where to look. Any hints? Probably somewhere in the code the $request->setLocale() must requested right?

simohammedhttp commented 6 years ago

Unfortunately, I dont't have any hint.

aik099 commented 6 years ago

If the requirements={"articlePath"=".+"} part of annotation is removed, then it works?

ceesvanegmond commented 6 years ago

@aik099 That doesn't solve the issue when requesting the locale from $request->getLocale(). I'm trying to solve this issue, kind of new go Symfony bundles, hadn't found an fix for it @aik099. Where do we need to fix this issue?

simohammedhttp commented 6 years ago

@aik099

I just checked the code source of the solution I have implemented :

jms_i18n_routing:
    default_locale: fr
    locales: [fr, ar, en]
    strategy: prefix_except_default

I used this route:

     * @Route("{_locale}{articlePath}", requirements={"_locale"="en|ar|", "articlePath"=".+"})
     * @Template()

The default 'fr' locale is made optional "en|ar|", look at the last vertical bar.

Now the following pages work great for both locales:

https://www.afa-advisory.com/conseil/développement-web-et-mobile (without fr, otherwise route won't be matched) https://www.afa-advisory.com/en/consulting/mobile-and-web-development