1 import { isBrowser } from "@utils/browser";
2 import i18next, { i18nTyped, Resource } from "i18next";
3 import { UserService } from "./services/UserService";
4 import { ar } from "./translations/ar";
5 import { bg } from "./translations/bg";
6 import { ca } from "./translations/ca";
7 import { cs } from "./translations/cs";
8 import { da } from "./translations/da";
9 import { de } from "./translations/de";
10 import { el } from "./translations/el";
11 import { en } from "./translations/en";
12 import { eo } from "./translations/eo";
13 import { es } from "./translations/es";
14 import { eu } from "./translations/eu";
15 import { fa } from "./translations/fa";
16 import { fi } from "./translations/fi";
17 import { fr } from "./translations/fr";
18 import { ga } from "./translations/ga";
19 import { gl } from "./translations/gl";
20 import { hr } from "./translations/hr";
21 import { id } from "./translations/id";
22 import { it } from "./translations/it";
23 import { ja } from "./translations/ja";
24 import { ko } from "./translations/ko";
25 import { nl } from "./translations/nl";
26 import { oc } from "./translations/oc";
27 import { pl } from "./translations/pl";
28 import { pt } from "./translations/pt";
29 import { pt_BR } from "./translations/pt_BR";
30 import { ru } from "./translations/ru";
31 import { sv } from "./translations/sv";
32 import { vi } from "./translations/vi";
33 import { zh } from "./translations/zh";
34 import { zh_Hant } from "./translations/zh_Hant";
36 export const languages = [
37 { resource: ar, code: "ar", name: "العربية" },
38 { resource: bg, code: "bg", name: "Български" },
39 { resource: ca, code: "ca", name: "Català" },
40 { resource: cs, code: "cs", name: "Česky" },
41 { resource: da, code: "da", name: "Dansk" },
42 { resource: de, code: "de", name: "Deutsch" },
43 { resource: el, code: "el", name: "Ελληνικά" },
44 { resource: en, code: "en", name: "English" },
45 { resource: eo, code: "eo", name: "Esperanto" },
46 { resource: es, code: "es", name: "Español" },
47 { resource: eu, code: "eu", name: "Euskara" },
48 { resource: fa, code: "fa", name: "فارسی" },
49 { resource: fi, code: "fi", name: "Suomi" },
50 { resource: fr, code: "fr", name: "Français" },
51 { resource: ga, code: "ga", name: "Gaeilge" },
52 { resource: gl, code: "gl", name: "Galego" },
53 { resource: hr, code: "hr", name: "Hrvatski" },
54 { resource: id, code: "id", name: "Bahasa Indonesia" },
55 { resource: it, code: "it", name: "Italiano" },
56 { resource: ja, code: "ja", name: "日本語" },
57 { resource: ko, code: "ko", name: "한국어" },
58 { resource: nl, code: "nl", name: "Nederlands" },
59 { resource: oc, code: "oc", name: "Occitan" },
60 { resource: pl, code: "pl", name: "Polski" },
61 { resource: pt, code: "pt", name: "Português" },
62 { resource: pt_BR, code: "pt_BR", name: "Português (Brasil)" },
63 { resource: ru, code: "ru", name: "Русский" },
64 { resource: sv, code: "sv", name: "Svenska" },
65 { resource: vi, code: "vi", name: "Tiếng Việt" },
66 { resource: zh, code: "zh", name: "中文 (简体)" },
67 { resource: zh_Hant, code: "zh-TW", name: "中文 (繁體)" },
70 const resources: Resource = {};
71 languages.forEach(l => (resources[l.code] = l.resource));
73 function format(value: any, format: any): any {
74 return format === "uppercase" ? value.toUpperCase() : value;
77 class LanguageDetector {
78 static readonly type = "languageDetector";
81 const langs: string[] = [];
84 UserService.Instance.myUserInfo?.local_user_view.local_user
85 .interface_language ?? "browser";
87 if (myLang !== "browser") langs.push(myLang);
89 if (isBrowser()) langs.push(...navigator.languages);
95 i18next.use(LanguageDetector).init({
97 compatibilityJSON: "v3",
98 supportedLngs: languages.map(l => l.code),
99 nonExplicitSupportedLngs: true,
100 // load: 'languageOnly',
101 // initImmediate: false,
104 interpolation: { format },
107 export const i18n = i18next as i18nTyped;