From a8a433b6f7c0ec7d30d571d9ecf2b6820865481f Mon Sep 17 00:00:00 2001 From: Benny Genel Date: Wed, 13 Jun 2018 02:50:13 +0300 Subject: [PATCH] i18next support --- components/layout.js | 60 +- components/page.js | 2 +- css/flag-sprites.scss | 26 + css/index.scss | 1 + helpers/i18next.js | 63 + index.js | 10 + npm-shrinkwrap.json | 6903 +++++++++++++++----------------- package.json | 4 + pages/_app.js | 34 + pages/index.js | 4 +- static/sprite-flags-24x24.png | Bin 0 -> 64332 bytes translations/de/common.json | 5 + translations/en/common.json | 5 + translations/en_GB/common.json | 5 + translations/en_US/common.json | 5 + translations/es/common.json | 5 + translations/fr/common.json | 5 + translations/it/common.json | 5 + translations/tr/common.json | 5 + 19 files changed, 3546 insertions(+), 3601 deletions(-) create mode 100644 css/flag-sprites.scss create mode 100644 helpers/i18next.js create mode 100644 pages/_app.js create mode 100644 static/sprite-flags-24x24.png create mode 100644 translations/de/common.json create mode 100644 translations/en/common.json create mode 100644 translations/en_GB/common.json create mode 100644 translations/en_US/common.json create mode 100644 translations/es/common.json create mode 100644 translations/fr/common.json create mode 100644 translations/it/common.json create mode 100644 translations/tr/common.json diff --git a/components/layout.js b/components/layout.js index 9546e66..3f6864a 100644 --- a/components/layout.js +++ b/components/layout.js @@ -92,7 +92,7 @@ export default class extends React.Component { - + @@ -170,16 +170,26 @@ export class UserMenu extends React.Component { this.handleSignoutSubmit = this.handleSignoutSubmit.bind(this) } - async handleSignoutSubmit(event) { - event.preventDefault() - - // Save current URL so user is redirected back here after signing out - const cookies = new Cookies() - cookies.set('redirect_url', window.location.pathname, { path: '/' }) + async handleSignoutSubmit(event) { + event.preventDefault() + + // Save current URL so user is redirected back here after signing out + const cookies = new Cookies() + cookies.set('redirect_url', window.location.pathname, { path: '/' }) + + await NextAuth.signout() + Router.push('/') + } - await NextAuth.signout() - Router.push('/') - } + changeLanguage = (e, lang) => { + e.preventDefault() + const { i18n } = this.props + i18n.reloadResources([lang]) + i18n.changeLanguage(lang, (err, t) => { + if (err) console.error('something went wrong loading', err); + console.info('Language Changed:', `${t('hello')} ${lang}`) + }) + } render() { if (this.props.session && this.props.session.user) { @@ -221,6 +231,36 @@ export class UserMenu extends React.Component { // If not signed in, display sign in button return (