Description
Localization of pathnames
Update: This is available as of [email protected]
, see the announcement thread.
We currently provide minimal documentation for localizing pathnames (see also the named routes example).
It would be helpful to have built-in support for this.
We could achieve this by accepting a route map:
// The `pathnames` object holds pairs of internal
// and external paths. Based on the locale, the
// corresponding external path will be picked.
const pathnames = {
// If all locales use the same pathname, a single
// external path can be used for all locales.
'/': '/',
'/blog': '/blog',
// If locales use different paths, you can
// specify each external path per locale.
'/about': {
en: '/about',
de: '/ueber-uns'
},
// Dynamic params are supported via square brackets
'/news/[articleSlug]-[articleId]': {
en: '/news/[articleSlug]-[articleId]',
de: '/neuigkeiten/[articleSlug]-[articleId]'
}
};
Proposed docs:
Prior art: https://v8.i18n.nuxtjs.org/guide/custom-paths
Streamlining of navigation APIs
Similar to the proposed factory function createLocalizedPathnamesNavigation
, we could offer a createSharedPathnamesNavigation
factory function that can be used to create the currently existing navigation APIs for non-localized pathnames.
This would:
- Streamline all imports to a single namespace
- Provide strict typing for the locales
- Make it easier to upgrade from shared pathnames to localized pathnames (you'll have to adjust pathnames with dynamic params though, but we can provide TypeScript support here)
import {createSharedPathnamesNavigation} from 'next-intl/navigation';
export const locales = ['en', 'de'] as const;
export const {Link, redirect, usePathname, useRouter} =
createSharedPathnamesNavigation({locales});
Potentially we could furthermore return a typed version of useLocale
from these functions.
Rollout plan: Introduce createSharedPathnamesNavigation
in a minor version, deprecate the previous imports and remove them in a major release.