Creation:2026-01-22Last update:2026-01-22
Reference this doc to your favorite AI assistantChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Implement custom URL rewrites"v8.0.01/22/2026
Edit this doc
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
Copy doc Markdown to clipboard
Documentation: getLocalizedPath Function in intlayer
Description
The getLocalizedPath function resolves a canonical path (internal application path) into its localized equivalent based on the provided locale and rewrite rules. It is particularly useful for generating SEO-friendly URLs that vary by language.
Key Features:
- Supports dynamic route parameters using the
[param]syntax. - Resolves paths according to custom rewrite rules defined in your configuration.
- Automatically handles fallback to the canonical path if no rewrite rule is found for the specified locale.
Function Signature
Parameters
Required Parameters
canonicalPath: string- Description: The internal application path (e.g.,
/about,/product/[id]). - Type:
string - Required: Yes
- Description: The internal application path (e.g.,
locale: Locales- Description: The target locale for which the path should be localized.
- Type:
Locales - Required: Yes
Optional Parameters
rewriteRules?: RoutingConfig['rewrite']- Description: An object defining custom rewrite rules. If not provided, it defaults to the
routing.rewriteproperty from your project's configuration. - Type:
RoutingConfig['rewrite'] - Default:
configuration.routing.rewrite
- Description: An object defining custom rewrite rules. If not provided, it defaults to the
Returns
- Type:
string - Description: The localized path for the specified locale.
Example Usage
Basic Usage (With Configuration)
If you have configured custom rewrites in your intlayer.config.ts:
Usage with Dynamic Routes
Manual Rewrite Rules
You can also pass manual rewrite rules to the function:
Related Functions
getCanonicalPath: Resolves a localized path back to its internal canonical path.getLocalizedUrl: Generates a fully localized URL (including protocol, host, and locale prefix).