i18n
Learn how to set up and use internationalization with Next.js and next-intl
MkSaaS uses next-intl for internationalization, allowing you to create multi-language applications with ease. With the built-in i18n support, you can create localized UI components, email templates, and more to provide a better experience for users worldwide.
Setup
Configuration
Internationalization settings are managed in the website.tsx
configuration file:
If you are setting up the environment, now you can go back to the Environment Setup guide and continue. The rest of this guide can be read later.
Environment Setup
Set up environment variables
Internationalization System Structure
The internationalization system in MkSaaS is designed with the following components:
This structure makes it easy to manage translations and integrate them into your application.
Core Features
- Multi-language support with next-intl integration
- Internationalized routing with prefixed locales
- Localized UI components for consistent user experience
- Localized email templates for communication
- URL generation with proper locale handling
- Automatic language detection based on user preferences
- Full support for Right-to-Left (RTL) languages
- Custom locale switcher component
Translation Files
MkSaaS uses JSON files for translations, located in the messages
directory. Each language has its own file, following the naming convention [locale].json
.
The structure of these files is hierarchical, allowing you to organize translations by feature or component:
Usage
Using Translations in React Components
MkSaaS provides an easy way to use translations in your React components with the useTranslations
hook:
For translations with parameters:
Using Translations in Server Components
For server components, use the getTranslations
function:
Localized Links and Navigation
To create links that respect the current locale, use the LocaleLink
component:
For programmatic navigation:
Localized Email Templates
MkSaaS includes support for sending localized emails using the same translation system:
To send a localized email:
Locale Components
MkSaaS provides two different locale switching components to give you flexibility in how you offer language selection to your users:
- LocaleSelector (
src/components/layout/locale-selector.tsx
) - LocaleSwitcher (
src/components/layout/locale-switcher.tsx
)
Both components provide a dropdown selection interface using the Select
component from the UI library. You can use either component depending on your needs.
Customization
Adding a New Language
-
Create a new translation file:
Create a new JSON file in the
messages
directory with the name of your locale (e.g.,fr.json
).You can copy the structure from
en.json
and translate all values:messages/fr.json -
Update the website configuration:
Add the new locale to your
website.tsx
configuration:src/config/website.tsx -
Handle incomplete translations:
The system automatically merges translations with the default language, so any missing translations will fall back to the default language (usually English).
Supporting Only One Language
If you only want to support one language in your application:
-
Keep only the language you want to support in the config file:
src/config/website.tsx -
Keep only the corresponding language file in the
messages
directory (e.g.,en.json
). -
Both
LocaleSelector
andLocaleSwitcher
components will automatically detect that only one language is configured and will not render in the UI. This ensures your UI remains clean without unnecessary language selection controls when they aren't needed.
Special Language Considerations
MkSaaS uses Fumadocs for documentation search functionality with proper internationalization support. For languages with special requirements (like Chinese, Arabic, etc.), you may need to configure additional settings:
For languages like Chinese, the search system uses the Mandarin tokenizer to properly index and search content. This requires special configuration as shown above, with adjusted threshold and tolerance settings for optimal search results.
The search configuration follows the recommendations from the Fumadocs Special Languages and Fumadocs Internationalization documentation.
Development Tools
i18n-ally VSCode Extension
For a smoother development experience when working with internationalization, we highly recommend installing the i18n-ally extension for your IDE (Visual Studio Code, Cursor, etc.).
i18n-ally
Learn more about i18n-ally setup
This powerful extension provides several benefits for multilingual application development:
- Inline Translation Preview: See translations directly in your code
- Missing Translation Detection: Highlights keys that are missing translations in certain languages
- Quick Translation Creation: Add new translations quickly with keyboard shortcuts
- Translation Management: Sort, rename, and refactor translation keys with ease
- Multiple Framework Support: Works with many i18n frameworks including next-intl
- Auto-completion: Suggests translation keys as you type
- Hover Information: View translations for all languages when hovering over a key
The extension integrates seamlessly with MkSaaS's internationalization structure and can significantly improve your workflow when managing translations across multiple languages.
Best Practices
- Use namespace-based keys: Organize translations using namespaces to make them more maintainable.
- Use parameters for dynamic content: Use parameters instead of string concatenation for dynamic content.
- Keep translations concise: Avoid lengthy translations that may break your UI layout.
- Consider context: Provide context in your keys to help translators understand how the text is used.
- Test all languages: Always test your application in all supported languages to ensure a good experience.
Next Steps
Now that you understand how to work with internationalization in MkSaaS, you might want to explore these related features: