Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

ri0n-dev
Copy link
Contributor

@ri0n-dev ri0n-dev commented Jun 5, 2025

Added a button to the navbar to select the language, allowing users to change the language.
  
image

@ri0n-dev ri0n-dev requested a review from mr-cheffy June 5, 2025 12:23
Comment on lines 32 to 34
i18n.LOCALES.map(locale => (
<a class="dropdown-item" href={getHref(locale.value)} aria-label={locale.label}>
<div class="dropdown-title">{locale.label}</div>
Copy link
Member

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)

Copy link
Contributor Author

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;
  }

Copy link
Member

@taroj1205 taroj1205 Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他のコンポーネントと重複する可能性があるのでLanguagesIcon.astroLanguageIcon.astroLocaleIcon.astroの様にIconを付けてください。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

わかりました。LanguagesIcon.astroに変更します。

@mr-cheffy
Copy link
Contributor

@ri0n-dev please don't close PRs and creating new ones, try to make all changes on this one only

@ri0n-dev
Copy link
Contributor Author

ri0n-dev commented Jun 6, 2025

@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.

@JosueGalRe
Copy link
Member

Hi, @ri0n-dev please solve merge conflicts :)

@ri0n-dev ri0n-dev closed this Jun 16, 2025
@ri0n-dev ri0n-dev reopened this Jul 11, 2025
@ri0n-dev
Copy link
Contributor Author

The commits must have verified signatures.
Thank you for your confirmation.

@ri0n-dev ri0n-dev requested a review from taroj1205 July 11, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants