Skip to content

Commit

Permalink
Merge pull request #139 from ubilabs/feat/i18n-language-switcher
Browse files Browse the repository at this point in the history
feat(i18n): language switcher
  • Loading branch information
pwambach authored Oct 10, 2019
2 parents f9c45b9 + a90fef4 commit c834ad3
Show file tree
Hide file tree
Showing 4 changed files with 35 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"
}
25 changes: 25 additions & 0 deletions src/scripts/components/language-selector/language-selector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, {FunctionComponent} from 'react';
import {FormattedMessage} from 'react-intl';
import {useDispatch} from 'react-redux';

import setLanguageAction, {Language} from '../../actions/set-language';

const languages = Object.values(Language);

const LanguageSelector: FunctionComponent<{}> = () => {
const dispatch = useDispatch();
const setLanguage = (language: Language) =>
dispatch(setLanguageAction(language));

return (
<ul>
{languages.map(language => (
<li key={language} onClick={() => setLanguage(language)}>
<FormattedMessage id={`language.${language}`} />
</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
Expand Up @@ -3,6 +3,8 @@ import {Link} from 'react-router-dom';

import styles from './menu.styl';

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

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

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

0 comments on commit c834ad3

Please sign in to comment.