From d60f37e770a7c7e04d8f87e36c93769453516446 Mon Sep 17 00:00:00 2001 From: Rion Date: Sun, 1 Jun 2025 19:11:15 +0900 Subject: [PATCH] feat: language selection dropdown --- .vscode/settings.json | 2 +- src/components/I18nSwitch.astro | 66 +++++++++++++++++++++++++++++++ src/components/NavBar.astro | 4 ++ src/icons/Languages.astro | 19 +++++++++ src/pages/[...locale]/about.astro | 2 +- 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/components/I18nSwitch.astro create mode 100644 src/icons/Languages.astro diff --git a/.vscode/settings.json b/.vscode/settings.json index 9974878..d499cd1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,7 +15,7 @@ "eslint.format.enable": false, "prettier.requireConfig": true, "[astro]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "astro-build.astro-vscode" }, "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" diff --git a/src/components/I18nSwitch.astro b/src/components/I18nSwitch.astro new file mode 100644 index 0000000..a28cd54 --- /dev/null +++ b/src/components/I18nSwitch.astro @@ -0,0 +1,66 @@ +--- +import { Dropdown, DropdownItems } from 'astro-navbar' +import LanguagesIcon from '~/icons/Languages.astro' +import { getLocale, getPath, getUI } from '~/utils/i18n' + +const locale = getLocale(Astro) +const getLocalePath = getPath(locale) + +const { + components: { + nav: { menu }, + }, +} = getUI(locale) + +interface Props { + label?: string + className?: string +} + +const { label, className = '' } = Astro.props +--- + + + + + + + + + + + diff --git a/src/components/NavBar.astro b/src/components/NavBar.astro index 66d60bb..82fbdb5 100644 --- a/src/components/NavBar.astro +++ b/src/components/NavBar.astro @@ -6,6 +6,7 @@ import ChevronDownIcon from '~/icons/ChevronDownIcon.astro' import DownloadIcon from '~/icons/DownloadIcon.astro' import MenuIcon from '~/icons/MenuIcon.astro' import { getLocale, getPath, getUI } from '~/utils/i18n' +import I18nSwitch from './I18nSwitch.astro' import Logo from './Logo.astro' import MobileMenu from './MobileMenu.astro' import ThemeSwitch from './ThemeSwitch.astro' @@ -106,6 +107,9 @@ const {
+
+ +
diff --git a/src/icons/Languages.astro b/src/icons/Languages.astro new file mode 100644 index 0000000..b3aa904 --- /dev/null +++ b/src/icons/Languages.astro @@ -0,0 +1,19 @@ +--- +const { class: className, ...props } = Astro.props +--- + + diff --git a/src/pages/[...locale]/about.astro b/src/pages/[...locale]/about.astro index 87a42b4..c05e96d 100644 --- a/src/pages/[...locale]/about.astro +++ b/src/pages/[...locale]/about.astro @@ -1,10 +1,10 @@ --- import { Image } from 'astro:assets' +import Button from '~/components/Button.astro' import Description from '~/components/Description.astro' import Layout from '~/layouts/Layout.astro' import { getLocale, getUI } from '~/utils/i18n' export { getStaticPaths } from '~/utils/i18n' -import Button from '~/components/Button.astro' const locale = getLocale(Astro)