From 8dd1a0927ad112c01e44473be9a8365da855da79 Mon Sep 17 00:00:00 2001 From: Yasuaki Uechi Date: Mon, 28 Mar 2022 16:28:47 +0900 Subject: [PATCH] fix: enable spanish translation --- CONTRIBUTING.md | 47 ++++++++++++++++++++++++++++++++++++--- src/components/Footer.tsx | 3 +++ src/util/i18n.ts | 3 ++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49cc240..9e16868 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -98,15 +98,16 @@ For example, `` will send a request ## Adding a new language -Suppose we'll add a support for Esperanto. +Suppose we'll add a support for Esperanto. First, copy `public/locales/en` folder and rename to `public/locales/eo` which is a language code for Esperanto. ```bash cd public/locales cp -r en eo -# edit eo/translation.json ``` -then edit `src/util/i18n.ts`: +Then translate `eo/translation.json`. + +After that, edit `src/util/i18n.ts`: ```patch - const TRANSLATION_VERSION = '2'; @@ -138,3 +139,43 @@ i18n }, }); ``` + +and `src/components/Footer.tsx`: + +```patch +const Languages = () => { + const { t } = useTranslation(); + + return ( + + {t('language')} + + + ); +}; +``` diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 58873a0..35800d9 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -46,6 +46,9 @@ const Languages = () => {
  • Português-BR
  • +
  • + Español +
  • ); diff --git a/src/util/i18n.ts b/src/util/i18n.ts index 9255cb4..3822ba2 100644 --- a/src/util/i18n.ts +++ b/src/util/i18n.ts @@ -5,7 +5,7 @@ import XHR from 'i18next-xhr-backend'; import LanguageDetector from 'i18next-browser-languagedetector'; import { initReactI18next } from 'react-i18next'; -const TRANSLATION_VERSION = '7'; +const TRANSLATION_VERSION = '8'; i18n .use(Backend) @@ -24,6 +24,7 @@ i18n 'zh-Hans': TRANSLATION_VERSION, 'zh-Hant': TRANSLATION_VERSION, 'pt-BR': TRANSLATION_VERSION, + es: TRANSLATION_VERSION, }, }, ],