Skip to content

Commit

Permalink
Use an own language switcher component for the app header
Browse files Browse the repository at this point in the history
Add a draft for toggling the language between en and de via a language
switcher in the app header.
  • Loading branch information
bjoernricks committed May 8, 2024
1 parent 095c4c1 commit 28d6dfe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/web/components/structure/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import useGmp from 'web/utils/useGmp';

import LogoutIcon from 'web/components/icon/logouticon';
import MySettingsIcon from 'web/components/icon/mysettingsicon';
import LanguageSwitch from './languageswitch';

const Header = () => {
const gmp = useGmp();
Expand Down Expand Up @@ -69,6 +70,7 @@ const Header = () => {
];
return (
<AppHeader
languageSwitch={<LanguageSwitch />}
menuPoints={menuPoints}
isLoggedIn={loggedIn}
username={username}
Expand All @@ -78,5 +80,3 @@ const Header = () => {
};

export default Header;

// vim: set ts=2 sw=2 tw=80:
39 changes: 39 additions & 0 deletions src/web/components/structure/languageswitch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {FlagDeIcon, FlagEnIcon} from '@greenbone/opensight-ui-components';
import {ActionIcon} from '@mantine/core';

import useLocale from 'web/hooks/useLocale';
import useTranslation from 'web/hooks/useTranslation';

const getNextLanguage = language => (language === 'en' ? 'de' : 'en');

const LanguageSwitch = () => {
const [language, changeLanguage] = useLocale();
const [_] = useTranslation();

const nextLanguage = getNextLanguage(language);
const titles = {
en: _('Switch language to English'),
de: _('Switch language to German'),
};

const handleLanguageChange = () => {
changeLanguage(nextLanguage);
};
return (
<ActionIcon
variant="transparent"
onClick={handleLanguageChange}
title={titles[nextLanguage]}
color="neutral.0"
>
{language === 'en' ? <FlagEnIcon /> : <FlagDeIcon />}
</ActionIcon>
);
};

export default LanguageSwitch;

0 comments on commit 28d6dfe

Please sign in to comment.