Skip to content

Creating LanguageSelector by using the localizePath function #123

Answered by yassinedoghri
Marionetko asked this question in Q&A
Discussion options

You must be logged in to vote

No problem, you don't have to use the LanguageSelector, you can create your own by using the localizePath function to render the right route.

Here's a basic dynamic example to render language selection using anchor tags:

---
import i18next from "i18next";
import { localizePath } from "astro-i18next";
import ISO6991 from "iso-639-1";

const supportedLanguages = i18next.languages;
const currentLanguage = i18next.language;
const { pathname } = Astro.url;
---

<div>
  {
    supportedLanguages.map((supportedLanguage: string) => {
      const route = localizePath(pathname, supportedLanguage);
      const nativeName = ISO6991.getNativeName(supportedLanguage);
      return (
        <a href={route}>

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Marionetko
Comment options

@yassinedoghri
Comment options

Answer selected by Marionetko
@Marionetko
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants