-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add localization and 'de' locale to website
- Loading branch information
Showing
8 changed files
with
212 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
import { getRelativeLocaleUrl } from "astro:i18n" | ||
import {languages, getLocalizedURL} from "../localize" | ||
--- | ||
<ul class="lang-options"> | ||
{Object.entries(languages).map(([l, labels]) => ( | ||
<li id={l} class="lang-option"> | ||
<a href={getLocalizedURL(Astro.url, l)}> | ||
<span class="lang-icon">{labels._}</span> | ||
<span>{labels[l as keyof typeof languages]} ({labels["en"]})</span> | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
|
||
<style scoped> | ||
.lang-options { | ||
list-style: none; | ||
} | ||
|
||
.lang-option a { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 1ch; | ||
} | ||
|
||
.lang-icon { | ||
font-size: 2rem; | ||
-webkit-text-stroke: 4px white; | ||
} | ||
|
||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const languages = { | ||
"en": {"_": "🇬🇧", "en": "English", "de": "Englisch"}, | ||
"de": {"_": "🇩🇪", "en": "German", "de": "Deutsch" } | ||
} | ||
export type Lang = keyof typeof languages | ||
|
||
export function getLocalizedURL(url: URL | string, lang: string) { | ||
const _url = new URL(url) | ||
const pathParts = _url.pathname.split("/") | ||
const pathWithoutLang = pathParts.slice(pathParts[1] in languages? 2: 1).join("/") | ||
return new URL(lang === "en" | ||
? `${_url.protocol}//${_url.host}/${pathWithoutLang}`: | ||
`${_url.protocol}//${_url.host}/${lang}/${pathWithoutLang}` | ||
) | ||
} | ||
|
||
export const msgResolver = (translations: Record<string, Record<string, string>>, lang: string) => (str: string) => (translations[str]?.[lang] ?? str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.