mirror of
https://github.com/zadam/trilium.git
synced 2025-11-04 13:39:01 +01:00
fix(website): language-specific pages not properly determined
This commit is contained in:
parent
c4c8fe23a9
commit
86aaa97809
@ -19,6 +19,7 @@ describe("swapLocale", () => {
|
|||||||
expect(swapLocaleInUrl("/ro/get-started", "ro")).toStrictEqual("/ro/get-started");
|
expect(swapLocaleInUrl("/ro/get-started", "ro")).toStrictEqual("/ro/get-started");
|
||||||
expect(swapLocaleInUrl("/en/get-started", "ro")).toStrictEqual("/ro/get-started");
|
expect(swapLocaleInUrl("/en/get-started", "ro")).toStrictEqual("/ro/get-started");
|
||||||
expect(swapLocaleInUrl("/ro/", "en")).toStrictEqual("/en/");
|
expect(swapLocaleInUrl("/ro/", "en")).toStrictEqual("/en/");
|
||||||
|
expect(swapLocaleInUrl("/ro", "en")).toStrictEqual("/en");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,13 @@ export function mapLocale(locale: string) {
|
|||||||
export function swapLocaleInUrl(url: string, newLocale: string) {
|
export function swapLocaleInUrl(url: string, newLocale: string) {
|
||||||
const components = url.split("/");
|
const components = url.split("/");
|
||||||
if (components.length === 2) {
|
if (components.length === 2) {
|
||||||
|
const potentialLocale = components[1];
|
||||||
|
const correspondingLocale = LOCALES.find(l => l.id === potentialLocale);
|
||||||
|
if (correspondingLocale) {
|
||||||
|
return `/${newLocale}`;
|
||||||
|
} else {
|
||||||
return `/${newLocale}${url}`;
|
return `/${newLocale}${url}`;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
components[1] = newLocale;
|
components[1] = newLocale;
|
||||||
return components.join("/");
|
return components.join("/");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user