From b05d1b1a0290e932957b965ac47b62b6f71cb4fe Mon Sep 17 00:00:00 2001 From: ov Date: Mon, 6 Jul 2020 10:36:45 +0100 Subject: [PATCH] Prototype with proposed i18n architecture (#1478) * Branch with i18n functionality * Translation files with new entries * includes Loader in index.jsx * Uses WithTranslation In Nav * New Namespace * Shortcuts Modal Complete * Preferences complete * About overlay title translated --- client/components/Nav.jsx | 147 +++++++++++++----- client/components/__test__/Nav.test.jsx | 3 +- .../__test__/__snapshots__/Nav.test.jsx.snap | 78 +++------- client/i18n.js | 38 +++++ client/index.jsx | 8 +- client/modules/IDE/components/About.jsx | 23 +-- .../IDE/components/KeyboardShortcutModal.jsx | 30 ++-- client/modules/IDE/components/Preferences.jsx | 58 +++---- client/modules/IDE/components/Toast.jsx | 4 +- client/modules/IDE/pages/IDEView.jsx | 18 ++- package-lock.json | 66 +++++++- package.json | 4 + server/server.js | 1 + server/views/index.js | 2 + translations/locales/en-US/translations.json | 115 ++++++++++++++ translations/locales/es-419/translations.json | 113 ++++++++++++++ 16 files changed, 550 insertions(+), 158 deletions(-) create mode 100644 client/i18n.js create mode 100644 translations/locales/en-US/translations.json create mode 100644 translations/locales/es-419/translations.json diff --git a/client/components/Nav.jsx b/client/components/Nav.jsx index dd7c800e..4c27d6fa 100644 --- a/client/components/Nav.jsx +++ b/client/components/Nav.jsx @@ -4,6 +4,8 @@ import { connect } from 'react-redux'; import { withRouter } from 'react-router'; import { Link } from 'react-router'; import classNames from 'classnames'; +import { withTranslation } from 'react-i18next'; +import i18next from 'i18next'; import * as IDEActions from '../modules/IDE/actions/ide'; import * as toastActions from '../modules/IDE/actions/toast'; import * as projectActions from '../modules/IDE/actions/project'; @@ -55,6 +57,10 @@ class Nav extends React.PureComponent { this.handleFocusForHelp = this.handleFocus.bind(this, 'help'); this.toggleDropdownForAccount = this.toggleDropdown.bind(this, 'account'); this.handleFocusForAccount = this.handleFocus.bind(this, 'account'); + this.toggleDropdownForLang = this.toggleDropdown.bind(this, 'lang'); + this.handleFocusForLang = this.handleFocus.bind(this, 'lang'); + this.handleLangSelection = this.handleLangSelection.bind(this); + this.closeDropDown = this.closeDropDown.bind(this); } @@ -163,6 +169,13 @@ class Nav extends React.PureComponent { this.setDropdown('none'); } + handleLangSelection(event) { + i18next.changeLanguage(event.target.value); + this.props.showToast(1500); + this.props.setToastText('LangChange'); + this.setDropdown('none'); + } + handleLogout() { this.props.logoutUser(); this.setDropdown('none'); @@ -233,7 +246,7 @@ class Nav extends React.PureComponent {