|
1 |
| -/* eslint-disable @typescript-eslint/explicit-function-return-type */ |
| 1 | +import i18n from 'i18next'; |
2 | 2 |
|
3 |
| -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ |
4 |
| -import { initReactI18next, useTranslation } from 'react-i18next'; |
5 |
| - |
6 |
| -import buildI18n, { namespaces } from '@graasp/translations'; |
| 3 | +import { initReactI18next } from 'react-i18next'; |
7 | 4 |
|
8 | 5 | import ar from '../langs/ar.json';
|
9 | 6 | import de from '../langs/de.json';
|
10 | 7 | import en from '../langs/en.json';
|
| 8 | +import es from '../langs/es.json'; |
11 | 9 | import fr from '../langs/fr.json';
|
12 | 10 | import it from '../langs/it.json';
|
13 | 11 |
|
14 |
| -const i18n = buildI18n().use(initReactI18next); |
| 12 | +export const DEFAULT_NAMESPACE = 'translations'; |
| 13 | +export const DEFAULT_LANG = 'en'; |
| 14 | +export const resources = { |
| 15 | + ar, |
| 16 | + de, |
| 17 | + en, |
| 18 | + es, |
| 19 | + fr, |
| 20 | + it, |
| 21 | +} as const; |
15 | 22 |
|
16 |
| -export const TEXT_ANALYSIS_NAMESPACE = 'text-analysis'; |
17 |
| -i18n.addResourceBundle('ar', TEXT_ANALYSIS_NAMESPACE, ar); |
18 |
| -i18n.addResourceBundle('de', TEXT_ANALYSIS_NAMESPACE, de); |
19 |
| -i18n.addResourceBundle('en', TEXT_ANALYSIS_NAMESPACE, en); |
20 |
| -i18n.addResourceBundle('fr', TEXT_ANALYSIS_NAMESPACE, fr); |
21 |
| -i18n.addResourceBundle('it', TEXT_ANALYSIS_NAMESPACE, it); |
| 23 | +declare module 'react-i18next' { |
| 24 | + interface CustomTypeOptions { |
| 25 | + defaultNS: typeof DEFAULT_NAMESPACE; |
| 26 | + resources: (typeof resources)['en']; |
| 27 | + } |
| 28 | +} |
22 | 29 |
|
23 |
| -export const useTextAnalysisTranslation = () => |
24 |
| - useTranslation(TEXT_ANALYSIS_NAMESPACE); |
25 |
| -export const useCommonTranslation = () => useTranslation(namespaces.common); |
26 |
| -export const useMessagesTranslation = () => useTranslation(namespaces.messages); |
27 |
| -export const useEnumsTranslation = () => useTranslation(namespaces.enums); |
28 |
| -export const useCategoriesTranslation = () => |
29 |
| - useTranslation(namespaces.categories); |
30 |
| -export const useChatboxTranslation = () => useTranslation(namespaces.chatbox); |
| 30 | +i18n.use(initReactI18next).init({ |
| 31 | + resources, |
| 32 | + fallbackLng: DEFAULT_LANG, |
| 33 | + lng: DEFAULT_LANG, |
| 34 | + // debug only when not in production |
| 35 | + debug: import.meta.env.DEV, |
| 36 | + ns: [DEFAULT_NAMESPACE], |
| 37 | + defaultNS: DEFAULT_NAMESPACE, |
| 38 | + keySeparator: false, |
| 39 | + interpolation: { |
| 40 | + escapeValue: false, |
| 41 | + formatSeparator: ',', |
| 42 | + }, |
| 43 | +}); |
31 | 44 |
|
32 | 45 | export default i18n;
|
0 commit comments