( pathname: string, locales?: string[] )
| 1867 | } |
| 1868 | |
| 1869 | export 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 | |
| 1896 | export function addLocaleOrDefault( |
| 1897 | pathname: string, |
no test coverage detected