You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Description:
Currently, when using next-intl with regional locales (e.g., de-DE, de-AT, de-CH) that share the same base language (de) and consequently should often share the same translated pathnames, the pathnames configuration requires explicitly defining the identical translated path for each regional locale.
For example, with locales: ['en', 'de-DE', 'de-AT', 'fr'], the configuration might look like this:
import{defineRouting}from'next-intl/routing';exportconstrouting=defineRouting({locales: ['en','de-DE','de-AT','fr'],defaultLocale: 'en',// Domains setup here...localePrefix: {mode: 'as-needed',},pathnames: {'/': '/','/products': {'de-DE': '/produkte',// Repetition for German locales'de-AT': '/produkte',// Repetition for German locales'fr': '/produits',// 'en' uses the internal '/products' due to default locale & 'as-needed'},'/products/[productId]': {'de-DE': '/produkte/[productId]',// Repetition'de-AT': '/produkte/[productId]',// Repetition'fr': '/produits/[productId]',},'/contact': {'de-DE': '/kontakt',// Repetition'de-AT': '/kontakt',// Repetition'fr': '/contactez-nous',}}});
This leads to repetition, especially when dealing with multiple regional variations (e.g., German in Germany, Austria, Switzerland) or other languages with similar regional needs. It violates the DRY (Don't Repeat Yourself) principle and makes the configuration harder to maintain.
This contrasts with the elegant solution for sharing message files (e.g., using de.json for both de-DE and de-AT) by leveraging new Intl.Locale(locale).language within getRequestConfig.
Describe the solution you'd like
Proposed Solution:
It would be highly beneficial to have a mechanism within the pathnames configuration to define a shared translated path for a group of regional locales or based on the base language. Possible syntax ideas could include:
Using an array of locales:
'/products': {['de-DE','de-AT']: '/produkte',// Define once for multiple German locales'fr': '/produits',}
Using the base language code (potentially ambiguous if base code is also in locales):
'/products': {'de': '/produkte',// Apply to all 'de-*' locales unless explicitly overridden'fr': '/produits',}
A dedicated syntax/property:
'/products': {// Apply '/produkte' to all 'de-*' localesbasePaths: {'de': '/produkte'},// Specific overrides if needed// 'de-CH': '/produkte-ch','fr': '/produits',}
The goal is to allow developers to define the common translated pathname (/produkte, /kontakt) only once for all relevant German-speaking locales, while still allowing specific overrides if necessary for a particular region.
Benefits:
Improved Maintainability: Reduces redundancy and makes the pathnames configuration cleaner and easier to manage.
DRY Principle: Adheres better to the DRY principle.
Consistency: Aligns the developer experience for pathnames closer to the flexibility offered for message handling.
Use Case:
Websites targeting multiple countries that share a common language (e.g., Germany/Austria/Switzerland, France/Belgium, US/UK/Canada/Australia) would significantly benefit from this feature by avoiding repetitive pathname definitions.
Describe alternatives you've considered
I have considered duplicating all pathnames for de-AT and de-DE and other countries that speak German language.
The text was updated successfully, but these errors were encountered:
Hey, thanks for the detailed feature request! I agree there might be a need for this, I'm currently not sure if it should be implemented within next-intl though.
You can realize this in userland with a function like this:
Alright, thank you amann, i think i have successfully implemented it with your instructions. It might be cool if this was built-in, but at least we have this option :-)
Is your feature request related to a problem? Please describe.
Description:
Currently, when using
next-intl
with regional locales (e.g.,de-DE
,de-AT
,de-CH
) that share the same base language (de
) and consequently should often share the same translated pathnames, thepathnames
configuration requires explicitly defining the identical translated path for each regional locale.For example, with
locales: ['en', 'de-DE', 'de-AT', 'fr']
, the configuration might look like this:This leads to repetition, especially when dealing with multiple regional variations (e.g., German in Germany, Austria, Switzerland) or other languages with similar regional needs. It violates the DRY (Don't Repeat Yourself) principle and makes the configuration harder to maintain.
This contrasts with the elegant solution for sharing message files (e.g., using
de.json
for bothde-DE
andde-AT
) by leveragingnew Intl.Locale(locale).language
withingetRequestConfig
.Describe the solution you'd like
Proposed Solution:
It would be highly beneficial to have a mechanism within the
pathnames
configuration to define a shared translated path for a group of regional locales or based on the base language. Possible syntax ideas could include:locales
):The goal is to allow developers to define the common translated pathname (
/produkte
,/kontakt
) only once for all relevant German-speaking locales, while still allowing specific overrides if necessary for a particular region.Benefits:
pathnames
configuration cleaner and easier to manage.Use Case:
Websites targeting multiple countries that share a common language (e.g., Germany/Austria/Switzerland, France/Belgium, US/UK/Canada/Australia) would significantly benefit from this feature by avoiding repetitive pathname definitions.
Describe alternatives you've considered
I have considered duplicating all pathnames for de-AT and de-DE and other countries that speak German language.
The text was updated successfully, but these errors were encountered: