import { I18nConfig } from '../types' ; import replaceBasename from './replaceBasename' ; function normalizeLocalePath ( pathname , i18nConfig , basename ? ) { pathname = replaceBasename ( pathname , basename ) ; const { defaultLocale , locales } = i18nConfig ; const subPaths = pathname . split ( '/' ) ; let detectedLocale = defaultLocale ; for ( const locale of locales ) { if ( subPaths [ 1 ] && subPaths [ 1 ] === locale ) { detectedLocale = locale ; subPaths . splice ( 1 , 1 ) ; pathname = subPaths . join ( '/' ) || '/' ; break ; } } return { pathname , detectedLocale , } ; } export default normalizeLocalePath ;