LandingBud uses next-intl (opens in a new tab) for localization. The library is a wrapper around the native NextJS i18n support, providing a more straightforward API to work with.
Essentially, using next-intl we get the following advantages:
- A global
localestate, meaning we always know the current locale that the user selected. This is also useful when we work with localized site content in thecontentfolder - A
useTranslationshook to access the translations in our components
Editing existing translations
The project comes with an English and a German locale. English is the default language and will be used as a fallback if a translation is missing in the selected locale.
- Translation string are stored in the
localesfolder. Each locale has its own JSON file, e.g.,en.jsonandde.json - Site content is stored in the
contentfolder. Each locale has its own folder, e.g.,enandde
Adding or changing a locale
Follow these steps to add a new locale. You can also use these steps to change the existing German locale to another one.
- Create a new JSON file in the
localesfolder, e.g.,fr.json- copy the content from theen.jsonfile and translate the strings - Create a new folder in the
contentfolder, e.g.,fr- copy the content from theenfolder and translate the markdown files - Open
src/i18n.tsand add your locale in the locales array - Open
src/middleware.tsand adapt the matcher inside the config object to include your new locale
export const config = {
// Match only internationalized pathnames
matcher: ["/", `/(de|en)/:path*`], // before
matcher: ["/", `/(de|en|fr)/:path*`], // after
};- Make sure that you have a country flag in
public/flagsfor the new locale. Nucleoapp has a great collection of flags that you can use. (opens in a new tab)