admin管理员组

文章数量:1123202

I am using next-intl to handle translations in my Next.js application. From my understanding, next-intl typically performs translations on the server side. However, I want to store the user's language (locale) preference in localStorage (client-side) and use that value to translate my website.

My goal is to:

Make the translation run entirely on the client side. Keep the translation logic within the components. I do not want to use cookies or rely on i18n routing for this functionality.

I followed the example provided in the official documentation: next-intl without i18n routing. However, this example assumes the locale is determined differently.

The translation works fine on it's own and I have a button to toggle between two languages which works fine to change the localStorage value as well, it's just linking the two together that's giving me a hard time.

How can I modify my setup to achieve client-side translations while respecting the user's locale stored in localStorage?

I followed the next-intl without i18n routing example to set up translations : /docs/getting-started/app-router/without-i18n-routing

本文标签: