From 0e0dba24835ff40aeb06522c0d13f74c60454531 Mon Sep 17 00:00:00 2001 From: martyanov-av Date: Tue, 25 Feb 2025 15:46:08 +0300 Subject: [PATCH] fix: static lang selector --- src/constants.ts | 2 ++ src/utils/index.ts | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 3055c427..f9868106 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,5 @@ import {Lang, TextSizes, Theme} from './models'; +import langs from './i18n'; export const DEFAULT_SETTINGS = { fullScreen: false, @@ -27,3 +28,4 @@ export const LEGACY_LANG_ITEMS = [ {value: Lang.En, text: 'English'}, {value: Lang.He, text: 'Hebrew'}, ]; +export const SUPPORTED_LANGS = Object.keys(langs); diff --git a/src/utils/index.ts b/src/utils/index.ts index 09041043..afafcadc 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -44,12 +44,15 @@ export function isActiveItem(router: Router, href: string, singlePage?: boolean) return normalizePath(router.pathname) === normalizePath(parse(href).pathname); } -export function getLangPath(router: Router, lang: string) { - const path = router.hash ? normalizeHash(router.hash) : normalizePath(router.pathname); - const route = path?.split('../') || []; - const routeLast = route[route.length - 1]; - const routeHtml = routeLast ? routeLast + '.html' : routeLast; - return `../${lang}/${routeHtml || ''}`; +export function getLangPath(router: Router, lang: string, href?: string) { + const {pathname, hash} = router; + const pathParts = pathname.split('/').filter(Boolean); + const newPath = pathParts.slice(1).join('/'); + const hrefWithoutHash = href?.split('#')[0]; + + return [`${lang}/`, newPath, hrefWithoutHash?.endsWith('.html') && '.html', hash] + .filter(Boolean) + .join(''); } export function isExternalHref(href: string) {