-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an own language switcher component for the app header
Add a draft for toggling the language between en and de via a language switcher in the app header.
- Loading branch information
1 parent
1e3f27f
commit ae319f0
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |