|
1 | 1 | import React from 'react';
|
2 | 2 | import ReactDOM from 'react-dom/client';
|
3 | 3 | import App from './App.tsx';
|
4 |
| -import i18nInstance, {getLang} from '@/utils/i18n'; |
5 |
| -import {initReactI18next} from 'react-i18next'; |
6 |
| -import {loader} from '@monaco-editor/react'; |
| 4 | +import i18nInstance, { getLang } from '@/utils/i18n'; |
| 5 | +import { initReactI18next } from 'react-i18next'; |
| 6 | +import dayjs from 'dayjs'; |
| 7 | +import duration from 'dayjs/plugin/duration'; |
| 8 | +import relativeTime from 'dayjs/plugin/relativeTime'; |
| 9 | +import utc from 'dayjs/plugin/utc'; |
| 10 | +import timezone from 'dayjs/plugin/timezone'; |
| 11 | +import { loader } from '@monaco-editor/react'; |
7 | 12 | import * as monaco from 'monaco-editor';
|
8 | 13 | import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
9 | 14 | // https://github.com/remcohaszing/monaco-yaml/issues/150
|
10 | 15 | import yamlWorker from '@/utils/workaround-yaml.worker?worker';
|
11 | 16 | import enTexts from '../locales/en-US.json';
|
12 | 17 | import zhTexts from '../locales/zh-CN.json';
|
13 |
| -import {initRoute} from '@/routes/route.tsx'; |
| 18 | +import { initRoute } from '@/routes/route.tsx'; |
14 | 19 |
|
| 20 | +dayjs.extend(duration); |
| 21 | +dayjs.extend(relativeTime); |
| 22 | +dayjs.extend(utc); |
| 23 | +dayjs.extend(timezone); |
15 | 24 | window.MonacoEnvironment = {
|
16 |
| - getWorker(_, label) { |
17 |
| - if (label === 'yaml') { |
18 |
| - return new yamlWorker(); |
19 |
| - } |
20 |
| - return new editorWorker(); |
21 |
| - }, |
| 25 | + getWorker(_, label) { |
| 26 | + if (label === 'yaml') { |
| 27 | + return new yamlWorker(); |
| 28 | + } |
| 29 | + return new editorWorker(); |
| 30 | + }, |
22 | 31 | };
|
23 |
| -loader.config({monaco}); |
| 32 | +loader.config({ monaco }); |
24 | 33 |
|
25 | 34 | i18nInstance
|
26 |
| - .use(initReactI18next) // passes i18n down to react-i18next |
27 |
| - .init({ |
28 |
| - debug: true, |
29 |
| - lng: getLang(), // if you're using a language detector, do not define the lng option |
30 |
| - fallbackLng: ['zh-CN'], |
31 |
| - resources: { |
32 |
| - zh: { |
33 |
| - translation: zhTexts, |
34 |
| - }, |
35 |
| - en: { |
36 |
| - translation: enTexts, |
37 |
| - }, |
38 |
| - }, |
39 |
| - interpolation: { |
40 |
| - escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape |
41 |
| - }, |
42 |
| - saveMissing: true, // send not translated keys to endpoint, |
43 |
| - react: { |
44 |
| - useSuspense: false, |
45 |
| - }, |
46 |
| - }) |
47 |
| - .then(() => { |
48 |
| - initRoute(); |
49 |
| - ReactDOM.createRoot(document.getElementById('root')!).render( |
50 |
| - <React.StrictMode> |
51 |
| - <App/> |
52 |
| - </React.StrictMode>, |
53 |
| - ); |
54 |
| - }) |
55 |
| - .catch(() => { |
56 |
| - |
57 |
| - }) |
| 35 | + .use(initReactI18next) // passes i18n down to react-i18next |
| 36 | + .init({ |
| 37 | + debug: true, |
| 38 | + lng: getLang(), // if you're using a language detector, do not define the lng option |
| 39 | + fallbackLng: ['zh-CN'], |
| 40 | + resources: { |
| 41 | + zh: { |
| 42 | + translation: zhTexts, |
| 43 | + }, |
| 44 | + en: { |
| 45 | + translation: enTexts, |
| 46 | + }, |
| 47 | + }, |
| 48 | + interpolation: { |
| 49 | + escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape |
| 50 | + }, |
| 51 | + saveMissing: true, // send not translated keys to endpoint, |
| 52 | + react: { |
| 53 | + useSuspense: false, |
| 54 | + }, |
| 55 | + }) |
| 56 | + .then(() => { |
| 57 | + initRoute(); |
| 58 | + ReactDOM.createRoot(document.getElementById('root')!).render( |
| 59 | + <React.StrictMode> |
| 60 | + <App /> |
| 61 | + </React.StrictMode>, |
| 62 | + ); |
| 63 | + }) |
| 64 | + .catch((err) => { |
| 65 | + console.error('initialization failed:', err); |
| 66 | + }); |
0 commit comments