Replies: 1 comment 4 replies
-
Interesting question! Yep, both approaches are fine. If there's no preference from your side, I'd go with Hope this helps! |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
First of all, congratulations on providing such an awesome library. After evaluating few i18n libraries on various factors, we decided to go with next-intl for localization feature within our project.
However, I would like to understand the best practice here in implementation as I'm new to Next.js (app router) and also still learning next-intl.
Context:
We have a Next.js 14.2.10 and we are using app router, also using the latest next-intl 3.19.4
Our app still uses client side components. That is, 'use client' in app\page.tsx (We may change this in future to move to RSC but not in plans yet).
And, we need to implement localization without "i18n routing"
I followed the example for a proof-of-concept example-app-router-without-i18n-routing and it works great.
Only difference is that we'll not be reading the locale from a cookie instead from a API call made client side after user is authenticated.
Questions:
Since our project has only client side components, I'm thinking I can get the messages in /layout.tsx for
NextIntlProvider
in two ways.Option 1: Use i18n/request.ts --> getRequestConfig to load messages (as showed in the example-app-router-without-i18n-routing example ). This works in my testing with our app with 'use client' in app\page.tsx.
app/layout.tsx
Option 2: Exclude
i18n/request.ts
file altogether and fetch the messages on client side within app\layout.tsx. This method will not use {getLocale, getMessages} from 'next-intl/server';app/layout.tsx
I'm not very sure if I'm thinking in the correct direction here. Can I use either of the options? If so, which one is recommended and best practice given we have all client side components and prefer to read user's locale from a react-query hook?
For my own understanding, is there a need/requirement to use
i18n/request.ts -> getRequestConfig
if an app is using mostly client side components with state dependency?getMesssages
vsuseMessages
From docs, I see useMessages() for regular components or getMessages() for async server components.
Does
useMessages
get messages fromi18n/request.ts --> getRequestConfig
?Beta Was this translation helpful? Give feedback.
All reactions