From 19e244999043c9fc813ba76822310c418b7f8369 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Sat, 11 Feb 2023 16:26:33 +0000 Subject: [PATCH] feat(language-selector): add languageMapping prop to rename languages of choice closes #116 --- README.md | 14 +++++++++++--- src/components/LanguageSelector.astro | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c64c2c8..8e64986 100644 --- a/README.md +++ b/README.md @@ -358,13 +358,21 @@ import { LanguageSelector } from "astro-i18next/components"; --- + + + ``` #### LanguageSelector Props -| Prop name | Type (default) | Description | -| --------- | ------------------ | --------------------------------------------------------- | -| showFlag | ?boolean (`false`) | Choose to display the language emoji before language name | +| Prop name | Type (default) | Description | +| --------------- | --------------------- | ------------------------------------------------------------------------------------------- | +| showFlag | ?boolean (`false`) | Choose to display the language emoji before language name | +| languageMapping | ?object (`undefined`) | Rewrite language names by setting the locale as key and the wording of your choice as value | ### HeadHrefLangs component diff --git a/src/components/LanguageSelector.astro b/src/components/LanguageSelector.astro index 1f9c075..5210682 100644 --- a/src/components/LanguageSelector.astro +++ b/src/components/LanguageSelector.astro @@ -4,8 +4,13 @@ import { localizePath } from "../.."; import localeEmoji from "locale-emoji"; import ISO6991 from "iso-639-1"; +interface languageMapping { + [localeCode: string]: string; +} + export interface Props extends astroHTML.JSX.SelectHTMLAttributes { showFlag?: boolean; + languageMapping?: languageMapping; } const supportedLanguages = i18next.languages; @@ -13,7 +18,7 @@ const currentLanguage = i18next.language; const { pathname } = Astro.url; -const { showFlag = false, ...attributes } = Astro.props; +const { showFlag = false, languageMapping, ...attributes } = Astro.props; ---