Front/translate refactor (#110)

* Front: i18n: Create component

* Front: Use new translation component

* Front: Translation COmpoent: Change props name

* Front: Fix merge
This commit is contained in:
Arthur Jamet
2022-11-24 17:20:45 +00:00
committed by GitHub
parent 620dae8316
commit 8546c86332
10 changed files with 124 additions and 56 deletions
+20
View File
@@ -0,0 +1,20 @@
import { translate } from "../i18n/i18n";
import { en } from "../i18n/Translations";
import { RootState, useSelector } from "../state/Store";
type TranslateProps = {
translationKey: keyof typeof en;
format?: (translated: string) => string;
}
/**
* Translation component
* @param param0
* @returns
*/
const Translate = ({ translationKey, format }: TranslateProps) => {
const selectedLanguage = useSelector((state: RootState) => state.language.value);
const translated = translate(translationKey, selectedLanguage);
return <>{format ? format(translated) : translated}</>;
}
export default Translate;