Internationalization
For internationaliztion supastarter integrates next-intl.
Why next-intl:
next-intl is a lightweight internationalization library for Next.js and comes
with support for both server and client components in the app router. It also
supports automatic language detection and url based language routing.
Usage
Server components
In server components you can use the can get the translate method like so:
If it is an async function you need to use the getTranslator
method instead and pass the locale
parameter:
Client components
In client components you can use the useTranslations
hook like so:
Translations
Translations are stored in the apps/web/locales
folder. The default locale is en
and the translations are stored in en.json
.
Add a new locale
To add a new locale you need to create a new file in the apps/web/locales
folder with the locale name as the file name. For example fr.json
for French.
Then register this locale in the apps/web/config.ts
file: