How to apply a button that changes the language on the website with next-intl #532
Replies: 3 comments 13 replies
-
This page outlines the current recommendations for this situation: https://next-intl-docs.vercel.app/docs/environments/server-client-components Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
i have the same issue (: how to solve? |
Beta Was this translation helpful? Give feedback.
-
@amannn , Hi, I am following this step guide: App Router setup without i18n routing import { headers } from "next/headers";
import { getRequestConfig } from "next-intl/server";
import { fetchTenant, fetchTranslationsForTenant } from "@/lib/fetchers";
export default getRequestConfig(async () => {
// Provide a static locale, fetch a user setting,
// read from `cookies()`, `headers()`, etc.
const domain = headers().get("host")?.replace(".localhost:3000", "") as string;
const tenant = await fetchTenant(domain);
const locale = tenant.locale;
const messages = await fetchTranslationsForTenant(domain);
return {
locale,
messages: messages[locale]
};
}); but how would I implement a locale switcher to change the languages based on the tenant supported locales? |
Beta Was this translation helpful? Give feedback.
-
Hello, I am getting more and more familiar with the library and the developer experience is very positive. However I have a question where I do not know how to solve my issue:
I have the following component:
Here I have a button that expands when I click on it and provides two options, German and English. Now when one user clicks on english I want to display the website in english and the same with german. This component is imported into my NavBar that is a Server component. However this is a client component because I have useState here. Which I need to expand the window where the options are hidden.
Right now as expected I get an error:
I followed the initial setup and use the beta for server components. It works great. But I struggle a bit how to apply the translation function here? Can anyone help me please?
Beta Was this translation helpful? Give feedback.
All reactions