hozana / next-translate-routes

Flexible and translated routes for Next.js without custom server
MIT License
115 stars 31 forks source link

Without Lang Prefix #20

Open KVRA opened 2 years ago

KVRA commented 2 years ago

My site is multi-domain ( next config like: )

...
  i18n: {
    locales: ['en-US', 'fr-FR', 'de-DE'],
    defaultLocale: 'en-US',
    domains: [
      {
        domain: 'dev.site.com',
        defaultLocale: 'en-US',
        http: true,
      },
      {
        domain: 'dev.site.fr',
        defaultLocale: 'fr-FR',
        http: true,
      },
    ],
...

But my links now have are like : "dev.site.fr/fr-FR/example" How to remove the language sufix since I already do it by domain ? I managed to do like that

  <Link
      href={href}
      as={translateUrl(href, router.locale, {
        withoutLangPrefix: true,
        format: 'string',
      })}
    >

is this the proper way ? Can I remove all the language prefix everywhere ? Also how to make the url "site.fr/sell" redirect to "site.fr/vendre" instead of redirecting with the lang prefix "site.fr/fr-FR/vendre/"

PS. THANKS FOR YOUR WORK ON THIS !

zergu commented 2 years ago

We have same issue with unintended adding locale to url path. We use language subdomains so we end up with broken urls.

cvolant commented 2 years ago

Subdomains... I didn't thought about that... Yes, it is not supported yet but it must be. I will post here when I start working on it, but I don't know yet when that will be possible. Feel free to work on it yourself : pull requests are welcome.

cvolant commented 1 year ago

I gave it a try here, but there is still some issues to tackle.

I tried to set localhost:3000 and localhost:3001 as different domains, then launch on instance on each port to test it locally, but even without next-translate-routes, it creates looping redirections. Do you have an idea why?

    domains: [
      {
        domain: 'localhost:3000',
        defaultLocale: 'en-US',
        http: true,
      },
      {
        domain: 'localhost:3001',
        defaultLocale: 'fr',
        http: true,
      },
    ],

I leave it as is for now, since I need to work on other subjects. Feel free to give it a try too, you can reuse my PR. I will post here again when I will work on it again.

KVRA commented 1 year ago

I have created a fork to make this, I only had to change one line in fileUrlToUrl https://github.com/KVRA/next-translate-routes/commit/4ef06b1e827a6e101b83de90a54ad6b213b68e02

But It should change not depenging on the env variable but instead based on the next config domains array, still works for me, currently using it on a big site :)

Where can I buy you a coffee ? Thanks

cvolant commented 1 year ago

I only had to change one line in fileUrlToUrl

Is it really enough?! :open_mouth: I am quite surprised because fileUrlToUrl is not the only place where a lang prefix is added... Do you have a way to test multi domain routing locally?

Where can I buy you a coffee ?

:smile: Well, if you really want to, you can do it here: https://don.hozana.org/je-donne

KVRA commented 1 year ago

Yes, it works and its working in prod for a while now, I use this functions to sitemap, alternative lang links etc... Just added dev.site.com and dev.site.de to my /etc/hosts pointing to 127.0.0.1 and added those domains to next.config

I didn't made a PR since I only E2E test without unit test :P but it works !

If you want to see in prod the English version is gindumac.com

cvolant commented 1 year ago

Ok, cool. It would be good to make something clean on the repo so that it works for everybody, but I need to test multi domain routing locally, and it did not work when I tried. Lately I have too much to do to be able to work on this (and we don't need it for ourselves) : so I need help to tackle this. Do you have a working config I could build on? I tried this but even without next-translate-routes, it does not work.