From ee62b850087d3e51eb19806a0d70aed8ef110be6 Mon Sep 17 00:00:00 2001 From: Alfred Melch Date: Fri, 31 Jan 2020 22:15:04 +0100 Subject: [PATCH] Add i18next --- package-lock.json | 30 ++++++++++++++++++++++++++++++ package.json | 2 ++ src/App.js | 6 +++++- src/components/LangSelect.js | 22 ++++++++++++++++++++++ src/components/Options.js | 10 ++++++---- src/i18n/de.json | 10 ++++++++++ src/i18n/en.json | 10 ++++++++++ src/i18n/index.js | 22 ++++++++++++++++++++++ src/index.js | 2 ++ 9 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 src/components/LangSelect.js create mode 100644 src/i18n/de.json create mode 100644 src/i18n/en.json create mode 100644 src/i18n/index.js diff --git a/package-lock.json b/package-lock.json index 1c7c799..94758f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5475,6 +5475,14 @@ } } }, + "html-parse-stringify2": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/html-parse-stringify2/-/html-parse-stringify2-2.0.1.tgz", + "integrity": "sha1-3FZwtyksoVi3vJFsmmc1rIhyg0o=", + "requires": { + "void-elements": "^2.0.1" + } + }, "html-webpack-plugin": { "version": "4.0.0-beta.11", "resolved": "https://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-4.0.0-beta.11.tgz", @@ -5650,6 +5658,14 @@ } } }, + "i18next": { + "version": "19.1.0", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-19.1.0.tgz", + "integrity": "sha512-ISbmukX4L6Dz0QoH9+EW1AnBw7j+NRLoMu9uLPMaNSSTP9Eie9/oUL0dOyWX15baB3gYOpkHJpGZRHOqcnl0ew==", + "requires": { + "@babel/runtime": "^7.3.1" + } + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -9497,6 +9513,15 @@ "integrity": "sha512-ueZzLmHltszTshDMwyfELDq8zOA803wQ1ZuzCccXa1m57k1PxSHfflPD5W9YIiTXLs0JTLzoj6o1LuM5N6zzNA==", "dev": true }, + "react-i18next": { + "version": "11.3.1", + "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-11.3.1.tgz", + "integrity": "sha512-S/CWHcnew1lXo8HeniGhBU5kTmPhZ4w4rtA4m/gDN07soCtKKYSAcLNm7zhwjI2OSR4Skd0vOtzNp/FzEEjxIw==", + "requires": { + "@babel/runtime": "^7.3.1", + "html-parse-stringify2": "2.0.1" + } + }, "react-icons": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-3.8.0.tgz", @@ -11548,6 +11573,11 @@ "integrity": "sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==", "dev": true }, + "void-elements": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-2.0.1.tgz", + "integrity": "sha1-wGavtYK7HLQSjWDqkjkulNXp2+w=" + }, "walk-back": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/walk-back/-/walk-back-4.0.0.tgz", diff --git a/package.json b/package.json index 849ea32..29dde99 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,10 @@ "axios": "^0.19.0", "classnames": "^2.2.6", "debounce": "^1.2.0", + "i18next": "^19.1.0", "react": "^16.12.0", "react-dom": "^16.12.0", + "react-i18next": "^11.3.1", "react-icons": "^3.8.0", "react-redux": "^7.1.3", "redux": "^4.0.4", diff --git a/src/App.js b/src/App.js index 3093bee..ad6d926 100644 --- a/src/App.js +++ b/src/App.js @@ -1,15 +1,19 @@ import React from 'react' +import { useTranslation } from 'react-i18next' import { RsvpReader } from './components/RsvpReader' import { GutenbergSearch } from './components/GutenbergSearch' import './App.css' +import { LangSelect } from './components/LangSelect' export const App = () => { + const { t } = useTranslation() return ( <>
-

The fast reader

+

{t('title')}

+
diff --git a/src/components/LangSelect.js b/src/components/LangSelect.js new file mode 100644 index 0000000..2c8ea95 --- /dev/null +++ b/src/components/LangSelect.js @@ -0,0 +1,22 @@ +import React from 'react' +import { useTranslation } from 'react-i18next' + +import { languages } from '../i18n' + +export const LangSelect = () => { + const { i18n } = useTranslation() + return ( + <> + + + ) +} diff --git a/src/components/Options.js b/src/components/Options.js index d2f7436..561c020 100644 --- a/src/components/Options.js +++ b/src/components/Options.js @@ -5,10 +5,12 @@ import { debounce } from 'debounce' import { setMaxLength, setWpm, setOffset, setLang } from '../store/actions' import { Slider } from './Slider' import { selectOffset, selectLang } from '../store/selectors' +import { useTranslation } from 'react-i18next' const availableLanguages = ['en', 'de'] export const Options = () => { + const { t } = useTranslation() const dispatch = useDispatch() const maxLength = useSelector(state => state.maxLength) const wpm = useSelector(state => state.wpm) @@ -17,23 +19,23 @@ export const Options = () => { return (
-

Options

+

{t('options.title')}

dispatch(setMaxLength(val)), 100)} /> dispatch(setWpm(val)), 50)} />