Skip to content

Commit

Permalink
Update i18n config of return-empty-string to false
Browse files Browse the repository at this point in the history
  • Loading branch information
mkubara committed Sep 8, 2019
1 parent de41a34 commit 1f5ee82
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
30 changes: 14 additions & 16 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -35,8 +28,13 @@ const App: React.FC = () => {
return (
<div className="App">
<header className="App-header">
<p>{t('Welcome to React')}</p>
<button onClick={() => setLang(lang === 'en' ? 'ja' : 'en')}>{t('change language')}</button>
<p>{t('ようこそ React と react-i18next へ。')}</p>
<small>{t('定義していない文字列')}</small>
<div>
<button onClick={() => setLang(lang === 'en' ? 'ja' : 'en')}>
{t('言語を切り替え')}
</button>
</div>
</header>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Welcome to React": "",
"change language": "",
"empty key": ""
"ようこそ React と react-i18next へ。": "Welcome to React and react-i18next.",
"定義していない文字列": "",
"言語を切り替え": "Change language"
}
6 changes: 3 additions & 3 deletions src/locales/ja.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Welcome to React": "",
"change language": "",
"empty key": ""
"ようこそ React と react-i18next へ。": "ようこそ React と react-i18next へ。",
"定義していない文字列": "",
"言語を切り替え": "言語を切り替え"
}

0 comments on commit 1f5ee82

Please sign in to comment.