MCPcopy Create free account
hub / github.com/vercel/vercel / normalizeLocalePath

Function normalizeLocalePath

packages/next/src/utils.ts:1869–1894  ·  view source on GitHub ↗
(
  pathname: string,
  locales?: string[]
)

Source from the content-addressed store, hash-verified

1867}
1868
1869export function normalizeLocalePath(
1870 pathname: string,
1871 locales?: string[]
1872): {
1873 detectedLocale?: string;
1874 pathname: string;
1875} {
1876 let detectedLocale: string | undefined;
1877 // first item will be empty string from splitting at first char
1878 const pathnameParts = pathname.split('/');
1879
1880 (locales || []).some(locale => {
1881 if (pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
1882 detectedLocale = locale;
1883 pathnameParts.splice(1, 1);
1884 pathname = pathnameParts.join('/') || '/';
1885 return true;
1886 }
1887 return false;
1888 });
1889
1890 return {
1891 pathname,
1892 detectedLocale,
1893 };
1894}
1895
1896export function addLocaleOrDefault(
1897 pathname: string,

Callers 4

serverBuildFunction · 0.90
filterStaticPagesFunction · 0.85
onPrerenderRouteInitialFunction · 0.85
onPrerenderRouteFunction · 0.85

Calls 2

splitMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected