-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b2f680
commit 1dd7815
Showing
12 changed files
with
115 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
import { languages } from '~/i18n/ui'; | ||
import { getLangFromUrl, useTranslations } from '~/i18n/utils'; | ||
import { HStack } from '../../../styled-system/jsx'; | ||
import { Link } from '../ui/link'; | ||
import { Text } from '../ui/text'; | ||
const lang = getLangFromUrl(Astro.url); | ||
const t = useTranslations(lang); | ||
const getURLWithLanguage = (value: string) => { | ||
return `/${lang}${value}`; | ||
}; | ||
const getCurrentURLWithLanguage = (language: string) => { | ||
const [, , currentPath] = Astro.url.pathname.split('/'); | ||
return `/${language}/${currentPath}`; | ||
}; | ||
const NAVIGATION_LINKS = [ | ||
{ label: t('common.home'), value: '/' }, | ||
{ label: t('common.about-me'), value: '/about' }, | ||
{ label: t('common.projects'), value: '/projects' }, | ||
{ label: t('common.note'), value: '/notes' }, | ||
{ label: t('common.contact'), value: '/contact' } | ||
]; | ||
--- | ||
|
||
<HStack _print={{ display: 'none' }} p={2} justifyContent="space-between"> | ||
<HStack> | ||
<Link href={getURLWithLanguage('/')}>{t('common.ham')}</Link> | ||
</HStack> | ||
<HStack gap="2"> | ||
{ | ||
NAVIGATION_LINKS.map(({ label, value }) => { | ||
return <Link href={getURLWithLanguage(value)}>{label}</Link>; | ||
}) | ||
} | ||
<Text> | </Text> | ||
{ | ||
Object.entries(languages).map((t) => { | ||
return <Link href={getCurrentURLWithLanguage(t[0])}>{t[1]}</Link>; | ||
}) | ||
} | ||
</HStack> | ||
</HStack> |
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,19 @@ | ||
import ui from 'i18n/index'; | ||
|
||
export const languages = { | ||
en: 'English', | ||
ja: '日本語' | ||
}; | ||
|
||
export const defaultLang = 'en'; | ||
|
||
export const routes = { | ||
en: { | ||
services: 'leistungen' | ||
}, | ||
ja: { | ||
services: 'prestations-de-service' | ||
} | ||
}; | ||
|
||
export { ui }; |
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,19 @@ | ||
import { defaultLang, ui } from './ui'; | ||
|
||
export function getLangFromUrl(url: URL) { | ||
const [, lang] = url.pathname.split('/'); | ||
if (lang in ui) return lang as keyof typeof ui; | ||
return defaultLang; | ||
} | ||
|
||
export function useTranslations<Lang extends keyof typeof ui = typeof defaultLang>(lang: Lang) { | ||
return function t< | ||
Collection extends keyof (typeof ui)[Lang], | ||
Key extends keyof (typeof ui)[Lang][Collection] | ||
>(key: `${string & Collection}.${string & Key}`): (typeof ui)[Lang][Collection][Key] { | ||
const [collection, translationKey] = key.split('.') as [Collection, Key]; | ||
return ( | ||
ui[lang][collection][translationKey] || ui[defaultLang as Lang][collection][translationKey] | ||
); | ||
}; | ||
} |
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,13 @@ | ||
--- | ||
import { Stack } from 'styled-system/jsx'; | ||
import Navigation from '~/components/layout/Navigation.astro'; | ||
import '../index.css'; | ||
import BaseLayout from './BaseLayout.astro'; | ||
--- | ||
|
||
<BaseLayout> | ||
<Stack gap="0" minH="100dvh"> | ||
<Navigation /> | ||
<Stack flex={1}><slot /></Stack> | ||
</Stack> | ||
</BaseLayout> |
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
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ export default { | |
'name-card': nameCard, | ||
note: note, | ||
project: project | ||
}; | ||
} as const; |
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ import ja from './ja'; | |
export default { | ||
en, | ||
ja | ||
}; | ||
} as const; |
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ export default { | |
'name-card': nameCard, | ||
note: note, | ||
project: project | ||
}; | ||
} as const; |