From 4235295d0f42f306444d05fab22bfaf76e54121c Mon Sep 17 00:00:00 2001 From: meriadec Date: Tue, 9 Jan 2018 14:48:41 +0100 Subject: [PATCH] add i18next --- package.json | 5 +++- src/components/App.js | 25 ++++++++++------- src/components/Home.js | 14 +++++++--- src/i18n/en/translation.yml | 3 ++ src/renderer/i18n.js | 19 +++++++++++++ yarn.lock | 56 +++++++++++++++++++++++++++++++------ 6 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 src/i18n/en/translation.yml create mode 100644 src/renderer/i18n.js diff --git a/package.json b/package.json index 48d0079a..b15dbe14 100644 --- a/package.json +++ b/package.json @@ -29,10 +29,13 @@ "electron": "1.7.9", "electron-devtools-installer": "^2.2.3", "history": "^4.7.2", - "ledger-node-js-hid": "github:loeck/ledger-node-js-hid#master", + "i18next": "^10.2.2", + "i18next-node-fs-backend": "^1.0.0", + "ledger-node-js-hid": "github:loeck/ledger-node-js-hid", "ledgerco": "^1.2.1", "react": "^16.2.0", "react-dom": "^16.2.0", + "react-i18next": "^7.3.0", "react-redux": "^5.0.6", "react-router": "^4.2.0", "react-router-dom": "^4.2.2", diff --git a/src/components/App.js b/src/components/App.js index 14b9f89b..a03f9fcc 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -6,6 +6,7 @@ import { ConnectedRouter } from 'react-router-redux' import { Provider, connect } from 'react-redux' import { Route } from 'react-router' import { ipcRenderer } from 'electron' +import { I18nextProvider } from 'react-i18next' import { devicesUpdate, deviceAdd, deviceRemove } from 'actions/devices' @@ -16,6 +17,8 @@ import SideBar from 'components/SideBar' import TopBar from 'components/TopBar' import Home from 'components/Home' +import i18n from '../renderer/i18n' + type Props = { deviceAdd: (device: Object) => void, deviceRemove: (device: Object) => void, @@ -50,17 +53,19 @@ class App extends PureComponent { return ( - - - - - - - + + + + + + + + + - - - + + + ) } diff --git a/src/components/Home.js b/src/components/Home.js index 0acf9282..6db8e28e 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -1,7 +1,9 @@ // @flow import React, { PureComponent } from 'react' +import { compose } from 'redux' import { connect } from 'react-redux' +import { translate } from 'react-i18next' type Props = { devices: Array, @@ -9,10 +11,14 @@ type Props = { class Home extends PureComponent { render() { - const { devices } = this.props - - return
{devices.map(device => device.path)}
+ const { devices, t } = this.props + return ( +
+ {t('common.cancel')} + {devices.map(device => device.path)} +
+ ) } } -export default connect(({ devices }: Props): Object => ({ devices }))(Home) +export default compose(connect(({ devices }: Props): Object => ({ devices })), translate())(Home) diff --git a/src/i18n/en/translation.yml b/src/i18n/en/translation.yml new file mode 100644 index 00000000..9c8213a5 --- /dev/null +++ b/src/i18n/en/translation.yml @@ -0,0 +1,3 @@ +common: + ok: Okay + cancel: Cancel diff --git a/src/renderer/i18n.js b/src/renderer/i18n.js new file mode 100644 index 00000000..ad677a7f --- /dev/null +++ b/src/renderer/i18n.js @@ -0,0 +1,19 @@ +// @flow + +import i18n from 'i18next' +import path from 'path' +import Backend from 'i18next-node-fs-backend' + +i18n.use(Backend).init({ + lng: 'en', + fallbackLng: 'en', + debug: true, + backend: { + loadPath: path.resolve(__dirname, '../i18n/{{lng}}/{{ns}}.yml'), + }, + react: { + wait: true, + }, +}) + +export default i18n diff --git a/yarn.lock b/yarn.lock index 750d791d..6f08a5fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -221,7 +221,7 @@ are-we-there-yet@~1.1.2: delegates "^1.0.0" readable-stream "^2.0.6" -argparse@^1.0.7: +argparse@^1.0.2, argparse@^1.0.7: version "1.0.9" resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86" dependencies: @@ -3499,14 +3499,14 @@ hoek@4.x.x: version "4.2.0" resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d" +hoist-non-react-statics@2.3.1, hoist-non-react-statics@^2.2.1, hoist-non-react-statics@^2.3.0, hoist-non-react-statics@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz#343db84c6018c650778898240135a1420ee22ce0" + hoist-non-react-statics@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb" -hoist-non-react-statics@^2.2.1, hoist-non-react-statics@^2.3.0, hoist-non-react-statics@^2.3.1: - version "2.3.1" - resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz#343db84c6018c650778898240135a1420ee22ce0" - home-or-tmp@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" @@ -3562,6 +3562,12 @@ html-minifier@^3.0.1, html-minifier@^3.2.3: relateurl "0.2.x" uglify-js "3.1.x" +html-parse-stringify2@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/html-parse-stringify2/-/html-parse-stringify2-2.0.1.tgz#dc5670b7292ca158b7bc916c9a6735ac8872834a" + dependencies: + void-elements "^2.0.1" + html-webpack-plugin@^2.30.1: version "2.30.1" resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-2.30.1.tgz#7f9c421b7ea91ec460f56527d78df484ee7537d5" @@ -3635,6 +3641,17 @@ https-browserify@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.1.tgz#3f91365cabe60b77ed0ebba24b454e3e09d95a82" +i18next-node-fs-backend@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/i18next-node-fs-backend/-/i18next-node-fs-backend-1.0.0.tgz#f5a625a3b287c1d098c7171b7dd376bb07299b59" + dependencies: + js-yaml "3.5.4" + json5 "0.5.0" + +i18next@^10.2.2: + version "10.2.2" + resolved "https://registry.yarnpkg.com/i18next/-/i18next-10.2.2.tgz#1f2dc55ca2e8d7e071f7aff9f78654ef7f003c0e" + iconv-lite@0.4.19, iconv-lite@^0.4.17, iconv-lite@^0.4.19, iconv-lite@~0.4.13: version "0.4.19" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" @@ -4005,6 +4022,13 @@ js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" +js-yaml@3.5.4: + version "3.5.4" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.5.4.tgz#f64f16dcd78beb9ce8361068e733ebe47b079179" + dependencies: + argparse "^1.0.2" + esprima "^2.6.0" + js-yaml@^3.10.0, js-yaml@^3.9.1: version "3.10.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc" @@ -4061,6 +4085,10 @@ json3@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1" +json5@0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.0.tgz#9b20715b026cbe3778fd769edccd822d8332a5b2" + json5@^0.5.0, json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" @@ -4140,9 +4168,9 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -"ledger-node-js-hid@github:loeck/ledger-node-js-hid#master": - version "" - resolved "git+ssh://git@github.com/loeck/ledger-node-js-hid.git#e345337a26b417028e7c5514634a98cd98f499ad" +"ledger-node-js-hid@github:loeck/ledger-node-js-hid": + version "0.1.0" + resolved "git+ssh://git@github.com/loeck/ledger-node-js-hid.git#58642a9bb703d0d65cb847402e84ac677710ef92" ledgerco@^1.2.1: version "1.2.1" @@ -5506,6 +5534,14 @@ react-hot-loader@^4.0.0-beta.12: redbox-react "^1.3.6" source-map "^0.6.1" +react-i18next@^7.3.0: + version "7.3.0" + resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-7.3.0.tgz#53de5afb6a3de53a0a9d09be7249c4748c0fc2db" + dependencies: + hoist-non-react-statics "2.3.1" + html-parse-stringify2 "2.0.1" + prop-types "^15.6.0" + react-redux@^5.0.6: version "5.0.6" resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.0.6.tgz#23ed3a4f986359d68b5212eaaa681e60d6574946" @@ -6845,6 +6881,10 @@ vm-browserify@0.0.4: dependencies: indexof "0.0.1" +void-elements@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec" + warning@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"