How to serve locale data based on different domains

Hi, im trying to work out the best way to serve localised content based on specific domains e.g.

I would create contentTypes and specify content based on the specific locale's in Prismic.

My question is around how to serve this data specifically based on the URL. Would something like the below work? locale could be specified by getting the URL with window.location.hostname and then providing the locale from a conditional statement?

`
prismic.api.getByType('content_type', { lang: locale }).then(res => {
...
})

Or is there a better way to do this?

Hey @luke1,

It looks like you want to use subdomains. I'm not aware of any way to run one instance of a Next.js app across multiple subdomains, so I can't recommend it or provide any instructions. Can you say more about how you plan to do this?

Otherwise, you could take a look at our i18n guide, which recommends a more conventional approach to routing an internationalized app:

Sam

Thanks @samlittlefair

The subdomain was just for example, could be done as example.com, example.com/us/, example.com/es/ etc.

Thanks for the link, looks like a good approach.

1 Like