Skip to content

Commit

Permalink
feat(i18n): add language switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
pwambach committed Oct 8, 2019
1 parent 60ce6c0 commit 44610cb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 3 additions & 1 deletion i18n/de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"layerSelector.main": "Haupt",
"layerSelector.compare": "Vergleich"
"layerSelector.compare": "Vergleich",
"language.en": "Englisch",
"language.de": "Deutsch"
}
4 changes: 3 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"layerSelector.main": "Main",
"layerSelector.compare": "Compare"
"layerSelector.compare": "Compare",
"language.en": "English",
"language.de": "German"
}
24 changes: 24 additions & 0 deletions src/scripts/components/language-selector/language-selector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, {FunctionComponent} from 'react';
import {FormattedMessage} from 'react-intl';
import {useDispatch} from 'react-redux';

import setLocaleAction, {Locale} from '../../actions/set-locale';

const locales = Object.values(Locale);

const LanguageSelector: FunctionComponent<{}> = () => {
const dispatch = useDispatch();
const setLocale = (locale: Locale) => dispatch(setLocaleAction(locale));

return (
<ul>
{locales.map(locale => (
<li key={locale} onClick={() => setLocale(locale)}>
<FormattedMessage id={`language.${locale}`} />
</li>
))}
</ul>
);
};

export default LanguageSelector;
4 changes: 4 additions & 0 deletions src/scripts/components/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, {FunctionComponent, useState} from 'react';
import styles from './menu.styl';

import LanguageSelector from '../language-selector/language-selector';

interface MenuItem {
id: string;
name: string;
Expand Down Expand Up @@ -45,6 +47,8 @@ const Menu: FunctionComponent<{}> = () => {
) : (
menuItem.name
)}

{menuItem.id === 'language' && <LanguageSelector />}
</li>
))}
</ul>
Expand Down

0 comments on commit 44610cb

Please sign in to comment.