Skip to content

Commit 06c4a65

Browse files
committed
feat: add i18n
1 parent 403493e commit 06c4a65

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

frontend/app/i18n/config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
- Copyright 2022 Sven Loesekann
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
import i18next from 'i18next';
14+
import { initReactI18next } from 'react-i18next';
15+
import translation from './en/translation.json';
16+
17+
i18next.use(initReactI18next).init({
18+
lng: 'en', // if you're using a language detector, do not define the lng option
19+
debug: true,
20+
resources: {
21+
en: {
22+
translation,
23+
},
24+
de: {
25+
translation
26+
}
27+
},
28+
// if you see an error like: "Argument of type 'DefaultTFuncReturn' is not assignable to parameter of type xyz"
29+
// set returnNull to false (and also in the i18next.d.ts options)
30+
// returnNull: false,
31+
});

frontend/app/i18n/de/translation.json

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"common": {
3+
"ok": "OK",
4+
"cancel": "Cancel"
5+
}
6+
}

frontend/app/login/login.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { useAtom } from "jotai";
2020
import type { FormEvent, BaseSyntheticEvent, ChangeEventHandler } from "react";
2121
import { postLogin, postSignin } from "~/service/http-client";
2222
import type { UserResponse } from "~/model/user";
23+
import '../i18n/config';
24+
import { useTranslation, Trans } from 'react-i18next';
2325

2426
interface MsgData {
2527
jwtToken?: string;
@@ -51,6 +53,7 @@ function TabPanel(props: TabPanelProps) {
5153
}
5254

5355
export function Login() {
56+
const { t } = useTranslation();
5457
const navigate = useNavigate();
5558
let controller: AbortController | null = null;
5659
const [globalUserName,setGlobalUserName] = useAtom(GlobalState.userNameState);
@@ -185,8 +188,8 @@ export function Login() {
185188
variant="standard"
186189
/>
187190
<div>
188-
<Button type="submit">Ok</Button>
189-
<Button onClick={handleCancel}>Cancel</Button>
191+
<Button type="submit">{t('common.ok')}</Button>
192+
<Button onClick={handleCancel}>{t('common.cancel')}</Button>
190193
</div>
191194
<div className={styles.responseMsg}>
192195
{[responseMsg].filter(value => !!value).map((value, index) =>

0 commit comments

Comments
 (0)