Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Add locale mapper documentation"v5.7.27/27/2025
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Locale Mapper
The Locale Mapper is a powerful utility that helps you work with internationalization data in your Intlayer application. It provides three main functions to transform and organize locale-specific data: localeMap, localeFlatMap, and localeRecord.
How Locale Mapper Works
The Locale Mapper operates on a LocaleData object that contains all the necessary information about a locale:
Copy the code to the clipboard
The mapper functions automatically generate this data for each locale in your configuration, taking into account:
- Your configured locales list
- The default locale setting
- Whether the default locale should be prefixed in URLs
Core Functions
localeMap
Transforms each locale into a single object using a mapper function.
Copy the code to the clipboard
Example: Creating route objects
Copy the code to the clipboard
localeFlatMap
Similar to localeMap, but the mapper function returns an array of objects that gets flattened into a single array.
Copy the code to the clipboard
Example: Creating multiple routes per locale
Copy the code to the clipboard
localeRecord
Creates a record object where each locale is a key mapping to a value transformed by the mapper function.
Copy the code to the clipboard
Example: Loading translation files
Copy the code to the clipboard
Setting Up Locale Mapper
The Locale Mapper automatically uses your Intlayer configuration, but you can override the defaults by passing parameters:
Using Default Configuration
Copy the code to the clipboard
Overriding Configuration
Copy the code to the clipboard
Advanced Usage Examples
Creating Navigation Menus
Copy the code to the clipboard
Generating Sitemap Data
Copy the code to the clipboard
Dynamic Translation Loading
Copy the code to the clipboard
Configuration Integration
The Locale Mapper seamlessly integrates with your Intlayer configuration:
- Locales: Automatically uses
configuration.internationalization.locales - Default Locale: Uses
configuration.internationalization.defaultLocale - URL Prefixing: Respects
configuration.middleware.prefixDefault
This ensures consistency across your application and reduces configuration duplication.
