diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2023-02-18 15:40:35 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2023-02-18 15:40:35 +0100 |
| commit | 06ce8fbab52c5c25a67a1518f1888b083b5edde3 (patch) | |
| tree | 244e0011111adbc37b9383dea8ede4374fed8d9a /dist/utils.js | |
| parent | fd6c3380f628c4de4e313c53152366a4484feeca (diff) | |
| download | auroraklinikken.no-06ce8fbab52c5c25a67a1518f1888b083b5edde3.tar.xz auroraklinikken.no-06ce8fbab52c5c25a67a1518f1888b083b5edde3.zip | |
.
Diffstat (limited to 'dist/utils.js')
| -rw-r--r-- | dist/utils.js | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/dist/utils.js b/dist/utils.js deleted file mode 100644 index d89663e..0000000 --- a/dist/utils.js +++ /dev/null @@ -1,30 +0,0 @@ -// Replaces the locale slug in a URL. -// -// If the `full` argument is set to `true`, the full URL is returned as a string. -// e.g. https://mywebsite.com/en/blog/article-1 => https://mywebsite.com/de/blog/article-1 -// -// Otherwise (default) the URL relative to the base is returned. -// e.g. https://mywebsite.com/en/blog/article-1 => /de/blog/article-1 -export const replaceLocaleInUrl = (url, locale, full = false) => { - const [, , ...rest] = url.pathname.split('/'); - const new_pathname = `/${[locale, ...rest].join('/')}`; - if (!full) { - return `${new_pathname}${url.search}`; - } - const newUrl = new URL(url.toString()); - newUrl.pathname = new_pathname; - return newUrl.toString(); -}; -export function fromLocalizedString(localizedString, locale) { - if (typeof localizedString === "string") - return localizedString; - // @ts-ignore - if (localizedString[locale]) - return localizedString[locale]; - // @ts-ignore - if (localizedString["nb"]) - return localizedString["nb"]; - // @ts-ignore - if (localizedString["en"]) - return localizedString["en"]; -} |
