@@ -14,8 +14,8 @@ export const useI18next = (ns?: Namespace, options?: UseTranslationOptions) => {
1414
1515 const { routed, defaultLanguage} = context ;
1616
17- const getUrlLanguage = ( language : string ) => {
18- return language !== defaultLanguage ? language : '' ;
17+ const getLanguagePath = ( language : string ) => {
18+ return language !== defaultLanguage ? `/ ${ language } ` : '' ;
1919 } ;
2020
2121 const removePrefix = ( pathname : string ) => {
@@ -33,15 +33,15 @@ export const useI18next = (ns?: Namespace, options?: UseTranslationOptions) => {
3333 } ;
3434
3535 const navigate = ( to : string , options ?: NavigateOptions < { } > ) => {
36- const urlLanguage = getUrlLanguage ( context . language ) ;
37- const link = routed ? `/ ${ urlLanguage } ${ to } ` : `${ to } ` ;
36+ const languagePath = getLanguagePath ( context . language ) ;
37+ const link = routed ? `${ languagePath } ${ to } ` : `${ to } ` ;
3838 return gatsbyNavigate ( link , options ) ;
3939 } ;
4040
4141 const changeLanguage = ( language : string , to ?: string , options ?: NavigateOptions < { } > ) => {
42- const urlLanguage = getUrlLanguage ( language ) ;
42+ const languagePath = getLanguagePath ( language ) ;
4343 const pathname = to || removeLocalePart ( removePrefix ( window . location . pathname ) ) ;
44- const link = `/ ${ urlLanguage } ${ pathname } ${ window . location . search } ` ;
44+ const link = `${ languagePath } ${ pathname } ${ window . location . search } ` ;
4545 localStorage . setItem ( LANGUAGE_KEY , language ) ;
4646 return gatsbyNavigate ( link , options ) ;
4747 } ;
0 commit comments