Skip to content

Commit 33ecdbf

Browse files
authored
Merge pull request #5 from Dialogue-Bot/DIAL-3-feat-implement-auth-fe
Dial 3 feat implement auth fe
2 parents e783a89 + 92bf0a3 commit 33ecdbf

File tree

20 files changed

+73
-63
lines changed

20 files changed

+73
-63
lines changed

client/src/components/btn-lang.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useTranslation } from 'react-i18next';
2-
import { Button } from './ui';
31
import { lngs } from '@/i18n';
42
import { ELang } from '@/types/share';
3+
import { useTranslation } from 'react-i18next';
4+
import { Button } from './ui';
55

66
export const ButtonLang = () => {
77
const { i18n } = useTranslation();
@@ -17,7 +17,7 @@ export const ButtonLang = () => {
1717
}}
1818
className="min-w-24"
1919
>
20-
{lngs.find((lng) => lng.code === i18n.language)?.name}
20+
{lngs[i18n.language as ELang]}
2121
</Button>
2222
);
2323
};

client/src/i18n.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

client/src/i18n/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ELang } from '@/types/share';
2+
import i18n from 'i18next';
3+
import LanguageDetector from 'i18next-browser-languagedetector';
4+
import { initReactI18next } from 'react-i18next';
5+
import resources from './resources';
6+
7+
export const lngs: Record<ELang, string> = {
8+
[ELang.EN]: 'English',
9+
[ELang.VI]: 'Tiếng Việt',
10+
};
11+
12+
i18n
13+
14+
.use(LanguageDetector)
15+
.use(initReactI18next)
16+
.init({
17+
debug: process.env.NODE_ENV === 'development',
18+
fallbackLng: ELang.EN,
19+
detection: {
20+
order: ['queryString', 'cookie', 'localstorage'],
21+
lookupLocalStorage: 'lang',
22+
lookupCookie: 'lang',
23+
lookupQuerystring: 'lang',
24+
caches: ['localStorage', 'cookie'],
25+
},
26+
ns: ['common', 'forms', 'register', 'login', 'layout'],
27+
resources,
28+
});
29+
export default i18n;

client/src/i18n/resources.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import commonEN from '@/locales/en/common.json';
2+
import forgotPassEN from '@/locales/en/forgot_pass.json';
3+
import formsEN from '@/locales/en/forms.json';
4+
import layoutEN from '@/locales/en/layout.json';
5+
import loginEN from '@/locales/en/login.json';
6+
import registerEN from '@/locales/en/register.json';
7+
import setPassEN from '@/locales/en/set_pass.json';
8+
import commonVI from '@/locales/vi/common.json';
9+
import forgotPassVI from '@/locales/vi/forgot_pass.json';
10+
import formsVI from '@/locales/vi/forms.json';
11+
import layoutVI from '@/locales/vi/layout.json';
12+
import loginVI from '@/locales/vi/login.json';
13+
import registerVI from '@/locales/vi/register.json';
14+
import setPassVI from '@/locales/vi/set_pass.json';
15+
import { ELang } from '@/types/share';
16+
17+
const resources = {
18+
[ELang.EN]: {
19+
common: commonEN,
20+
forms: formsEN,
21+
register: registerEN,
22+
login: loginEN,
23+
layout: layoutEN,
24+
forgot_pass: forgotPassEN,
25+
set_pass: setPassEN,
26+
},
27+
[ELang.VI]: {
28+
common: commonVI,
29+
forms: formsVI,
30+
register: registerVI,
31+
login: loginVI,
32+
layout: layoutVI,
33+
forgot_pass: forgotPassVI,
34+
set_pass: setPassVI,
35+
},
36+
} as const;
37+
38+
export default resources;

client/src/i18next.d.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import 'i18next';
2+
import resources from './i18n/resources';
23

34
declare module 'i18next' {
45
interface CustomTypeOptions {
5-
resources: {
6-
login: typeof import('../public/locales/en/login.json');
7-
common: typeof import('../public/locales/en/common.json');
8-
layout: typeof import('../public/locales/en/layout.json');
9-
forms: typeof import('../public/locales/en/forms.json');
10-
register: typeof import('../public/locales/en/register.json');
11-
forgot_pass: typeof import('../public/locales/en/forgot_pass.json');
12-
set_pass: typeof import('../public/locales/en/set_pass.json');
13-
};
6+
resources: typeof resources.en;
147
}
158
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)