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:
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.
Example: Creating route objects
localeFlatMap
Similar to localeMap, but the mapper function returns an array of objects that gets flattened into a single array.
Example: Creating multiple routes per locale
localeRecord
Creates a record object where each locale is a key mapping to a value transformed by the mapper function.
Example: Loading translation files
Setting Up Locale Mapper
The Locale Mapper automatically uses your Intlayer configuration, but you can override the defaults by passing parameters:
Using Default Configuration
Overriding Configuration
Advanced Usage Examples
Creating Navigation Menus
Generating Sitemap Data
Dynamic Translation Loading
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.