All questions

Strapi i18n plus Croct, how does locale selection work per slot?

Asked by meiling on

Mmeiling

We are a Singapore retailer serving en, zh, and ms locales from Strapi i18n. Our pages already resolve the right Strapi locale from the URL, so I expected the Croct slot to follow the page locale automatically.

Actual behavior: the slot always returns content in the default locale, even on /zh pages. The default fallback from Strapi is fine since we pass it ourselves, but variant content authored in Croct comes back in English

Is there a way to tell the slot which locale the page is in, or does it only ever serve one locale?

Was this helpful?

1 answer

Kkenji_m

The slot does not infer the locale from the URL, you have to pass it. All the fetching APIs accept a preferredLocale option: fetch in the JS SDK, useContent in React, and fetchContent on the Next.js server side. So wire your route locale through:

const content = await fetchContent('home-hero', {    preferredLocale: locale, // 'zh', 'ms', 'en'});

If most of your app runs in one locale you can also set defaultPreferredLocale in the plug options instead of passing it per call.

One thing to check on the workspace side: localization with per-locale default content is an add-on, so make sure it is enabled and that the experience actually has zh and ms content authored. If a locale has no content, you get the default locale back, which matches what you are seeing. The localization docs cover the option on each SDK.

Was this helpful?
Still have questions?