summaryrefslogtreecommitdiff
path: root/frontend/src/start.tsx
blob: cc2c02c2d8caf14c68c97e6d94f14af334076522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import i18n from 'i18next';
import Backend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';

import PluginLoader from './plugin-loader';
import { DeckyUpdater } from './updater';

declare global {
  interface Window {
    DeckyPluginLoader: PluginLoader;
    DeckyUpdater?: DeckyUpdater;
    importDeckyPlugin: Function;
    deckyHasLoaded: boolean;
    deckyHasConnectedRDT?: boolean;
    deckyAuthToken: string;
    DFL?: any;
  }
}

(async () => {
  i18n
    .use(Backend)
    .use(initReactI18next)
    .init({
      load: 'currentOnly',
      detection: {
        order: ['querystring', 'navigator'],
        lookupQuerystring: 'lng',
      },
      //debug: true,
      lng: navigator.language,
      fallbackLng: 'en-US',
      interpolation: {
        escapeValue: true,
      },
      returnEmptyString: false,
      backend: {
        loadPath: 'http://127.0.0.1:1337/locales/{{lng}}.json',
        customHeaders: {
          Authentication: window.deckyAuthToken,
        },
        requestOptions: {
          credentials: 'include',
        },
      },
    });

  window.DeckyPluginLoader?.dismountAll();
  window.DeckyPluginLoader?.deinit();
  window.DeckyPluginLoader = new PluginLoader();
  window.DeckyPluginLoader.init();
  window.importDeckyPlugin = function (name: string, version: string) {
    window.DeckyPluginLoader?.importPlugin(name, version);
  };
})();

export default i18n;