next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

decoupled_router and locale

Open spiderneo opened this issue 3 years ago • 3 comments

Hi, i'm currently working to translate my next App

My Drupal is configured to use the URL to set the language image

I found that the function translatePath don't use locale to search for a path. So if i follow the request https://dev.sneo.fr/router/translate-path?path=en will be redirected to FR (which is the default lang) https://dev.sneo.fr/fr/router/translate-path?path=en and no result is found.

if I use the EN prefix instead it work and the EN version of my page is returned https://dev.sneo.fr/en/router/translate-path?path=en

Do i missed something ? or is it the normal behavior ?

https://github.com/chapter-three/next-drupal/blob/7f27653649a8f62b2d33bf1634c1083151d62b2b/packages/next-drupal/src/client.ts#L904-L931

spiderneo avatar Jan 27 '23 13:01 spiderneo

For those who are interested, this is my patch.

add_locale_to_translatePath.patch

spiderneo avatar Jan 27 '23 14:01 spiderneo

I checked you patch but it was not working for me. This is for sure problem with path resolution in decoupled_router.

I had the same issue, i have 2 languages in front, one is EN, it was set as default in front and backend. Drupal does not recommend to switch language after configuration of "Content language and translation". Moreover i am using Paragraphs module in Drupal, which has specific apporach to language handling. Since i use the same default language in both frontend and backend all works good, second language, non default is also working. But when i change in front default language to other one translation is not working i am getting for both EN version. The way i solved an issue i by using approach with "default" locale, which is descibed here: https://github.com/vercel/next.js/discussions/18419

Hardcoded en you can switch to whatever default language (i called it defaultLanguagePseudo) should it be for your page. Do not confuse this defaultLanguagePseudo with defaultLanguage which i left both in frontend adn backend to EN.

p0zi avatar Feb 08 '23 15:02 p0zi

@shadcn What're your thoughts on this? Seems like translatePath should maybe take locale into account, like in the patch from @spiderneo

Reason being, if I have a node that is only in en-ca, not fr-ca, and en-ca is the Drupal default language, then all requests to the router hit the /en-ca/router/translate-path:

/en-ca/router/translate-path?path=/fr-ca/english-only&_format=json -> this returns the english node, which for our fr-ca site, I don't want to show. /fr-ca/router/translate-path?path=/fr-ca/english-only&_format=json -> this returns:

{
"message": "Unable to resolve path /fr-ca/english-only.",
"details": "None of the available methods were able to find a match for this path."
}

as I would expect.

Now, I think we've done some work in Drupal not to return default language content if content for the requesting locale doesn't exist - but I don't know enough about decoupled_router to know if it should always be getting queried with the correct locale as prefix.

Anyway I'm gonna try out that patch above, but figured you'd have more insight.

MartinDavi avatar May 19 '23 12:05 MartinDavi