-
Notifications
You must be signed in to change notification settings - Fork 206
feat: language selection dropdown #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/components/I18nSwitch.astro
Outdated
i18n.LOCALES.map(locale => ( | ||
<a class="dropdown-item" href={getHref(locale.value)} aria-label={locale.label}> | ||
<div class="dropdown-title">{locale.label}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ブランチを最新にしたら~/utils/i18n
からgetPath
をインポートして以下のようにできるようになるはずです。
getPath(locale.value)(Astro.url.pathname)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
できましたが、デフォルト言語の場合だと/ja/などの言語を表すディレクトリが消されず、何も起きませんでした。
そこで、/utils/i18nを変更し、デフォルト言語が選択された場合、言語を表すディレクトリを削除するようなコードに変更しました。
export const getPath =
(locale?: Locale): ((arg0: string) => string) =>
(path: string) => {
const localeDirs = CONSTANT.I18N.LOCALES.map(({ value }) => value);
const cleanedPath = path.replace(new RegExp(`^/(${localeDirs.join('|')})(/|$)`), '/');
if (locale && locale !== CONSTANT.I18N.DEFAULT_LOCALE && !path.startsWith(`/${locale}`)) {
return `/${locale}${path.startsWith('/') ? '' : '/'}${path}`;
}
return cleanedPath;
}
src/icons/Languages.astro
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
他のコンポーネントと重複する可能性があるのでLanguagesIcon.astro
、LanguageIcon.astro
やLocaleIcon.astro
の様にIconを付けてください。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
わかりました。LanguagesIcon.astroに変更します。
@ri0n-dev please don't close PRs and creating new ones, try to make all changes on this one only |
Sorry about that. I had to close it because it contained unnecessary changes. I won't be creating any more. |
Hi, @ri0n-dev please solve merge conflicts :) |
The commits must have verified signatures. |
Added a button to the navbar to select the language, allowing users to change the language.
