Internationalization
Learn how to use internationalization in supastarter.
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 getTranslations
method:
Client components
In client components you can use the useTranslations
hook like so:
Translations
Translations are defined in the packages/i18n/translations
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 /packages/i18n/translations
folder with the locale name as the file name. For example fr.json
for French.
Then register this locale in the config/index.ts
file:
Disable internationalization
If you don't want to use internationalization or only want to activate it later on, you can disable it by setting the i18n.enabled
flag to false
in the config/index.ts
file.