Skip to content

Commit b5baf99

Browse files
committed
feat: make translation work
1 parent b5e9288 commit b5baf99

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

frontend/app/i18n/config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@
1313
import i18next from 'i18next';
1414
import { initReactI18next } from 'react-i18next';
1515
import LanguageDetector from 'i18next-browser-languagedetector';
16-
import translation from './en/translation.json';
16+
import translationEn from './en/translation.json';
17+
import translationDe from './de/translation.json';
1718

1819
i18next.use(initReactI18next).use(LanguageDetector).init({
1920
supportedLngs: ['de', 'en'],
2021
fallbackLng: 'en',
2122
debug: true,
23+
interpolation: { escapeValue: false },
2224
resources: {
2325
en: {
24-
translation,
26+
translation: translationEn
2527
},
2628
de: {
27-
translation
29+
translation: translationDe
2830
}
2931
},
3032
// if you see an error like: "Argument of type 'DefaultTFuncReturn' is not assignable to parameter of type xyz"
3133
// set returnNull to false (and also in the i18next.d.ts options)
3234
// returnNull: false,
33-
});
35+
});
36+
37+
export default i18next;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"common": {
3+
"ok": "OK",
4+
"cancel": "Abbrechen",
5+
"message": "Nachricht",
6+
"language": "Sprache",
7+
"english": "Englisch",
8+
"german": "Deutsch"
9+
},
10+
"login": {
11+
"username": "Benutzername",
12+
"password": "Passwort",
13+
"login": "Login",
14+
"signin": "Registrieren"
15+
}
16+
}

frontend/app/login/login.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function TabPanel(props: TabPanelProps) {
5353
}
5454

5555
export function Login() {
56-
const { t } = useTranslation();
56+
const { t, i18n } = useTranslation();
5757
const navigate = useNavigate();
5858
let controller: AbortController | null = null;
5959
const [globalUserName,setGlobalUserName] = useAtom(GlobalState.userNameState);
@@ -67,6 +67,7 @@ export function Login() {
6767
const [password2, setPassword2] = useState('');
6868
const [responseMsg, setResponseMsg] = useState('');
6969
const [activeTab, setActiveTab] = useState(0);
70+
const [language, setLanguage] = React.useState('en');
7071

7172
const handleChangeUsername: ChangeEventHandler<HTMLInputElement> = (event) => {
7273
setUserName(event.currentTarget.value as string);
@@ -152,9 +153,9 @@ export function Login() {
152153
};
153154
}
154155

155-
const [language, setLanguage] = React.useState('en');
156156
const handleLanguageChange = (event: SelectChangeEvent) => {
157157
setLanguage(event.target.value);
158+
i18n.changeLanguage(event.target.value).then();
158159
};
159160

160161
return (<Dialog open={globalLoginModal} onClose={handleClose} className="backDrop">

0 commit comments

Comments
 (0)