From 1f5ee8237a16b86b62451284e1b0e73ddede6022 Mon Sep 17 00:00:00 2001 From: mkubara Date: Sun, 8 Sep 2019 17:49:41 +0900 Subject: [PATCH] Update i18n config of return-empty-string to false --- src/App.tsx | 30 ++++++++++++++---------------- src/locales/en.json | 6 +++--- src/locales/ja.json | 6 +++--- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8b2f814..27fc8d3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,26 +2,19 @@ import React, { useState, useEffect } from 'react'; import i18n from 'i18next'; import { initReactI18next, useTranslation } from 'react-i18next'; +import enJson from './locales/en.json'; +import jaJson from './locales/ja.json'; + import './App.css'; i18n.use(initReactI18next).init({ resources: { - en: { - translation: { - 'Welcome to React': 'Welcome to React and react-i18next.', - 'change language': 'change language', - }, - }, - ja: { - translation: { - 'Welcome to React': 'ようこそ React と react-i18next へ。', - 'change language': '言語を切り替え', - }, - }, + en: { translation: enJson }, + ja: { translation: jaJson }, }, lng: 'ja', - fallbackLng: 'ja', - interpolation: { escapeValue: false }, + fallbackLng: false, + returnEmptyString: false, }); const App: React.FC = () => { @@ -35,8 +28,13 @@ const App: React.FC = () => { return (
-

{t('Welcome to React')}

- +

{t('ようこそ React と react-i18next へ。')}

+ {t('定義していない文字列')} +
+ +
); diff --git a/src/locales/en.json b/src/locales/en.json index c9e7668..0f83f0a 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1,5 +1,5 @@ { - "Welcome to React": "", - "change language": "", - "empty key": "" + "ようこそ React と react-i18next へ。": "Welcome to React and react-i18next.", + "定義していない文字列": "", + "言語を切り替え": "Change language" } \ No newline at end of file diff --git a/src/locales/ja.json b/src/locales/ja.json index c9e7668..2797a99 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -1,5 +1,5 @@ { - "Welcome to React": "", - "change language": "", - "empty key": "" + "ようこそ React と react-i18next へ。": "ようこそ React と react-i18next へ。", + "定義していない文字列": "", + "言語を切り替え": "言語を切り替え" } \ No newline at end of file