index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React from 'react';
  16. import ReactDOM from 'react-dom/client';
  17. import { BrowserRouter } from 'react-router-dom';
  18. import '@douyinfe/semi-ui/dist/css/semi.css';
  19. import { UserProvider } from './context/User';
  20. import 'react-toastify/dist/ReactToastify.css';
  21. import { StatusProvider } from './context/Status';
  22. import { ThemeProvider } from './context/Theme';
  23. import PageLayout from './components/layout/PageLayout.js';
  24. import './i18n/i18n.js';
  25. import './index.css';
  26. import { LocaleProvider } from '@douyinfe/semi-ui';
  27. import { useTranslation } from 'react-i18next';
  28. import zh_CN from '@douyinfe/semi-ui/lib/es/locale/source/zh_CN';
  29. import en_GB from '@douyinfe/semi-ui/lib/es/locale/source/en_GB';
  30. // 欢迎信息(二次开发者未经允许不准将此移除)
  31. // Welcome message (Do not remove this without permission from the original developer)
  32. if (typeof window !== 'undefined') {
  33. console.log('%cWe ❤ NewAPI%c Github: https://github.com/QuantumNous/new-api',
  34. 'color: #10b981; font-weight: bold; font-size: 24px;',
  35. 'color: inherit; font-size: 14px;');
  36. }
  37. function SemiLocaleWrapper({ children }) {
  38. const { i18n } = useTranslation();
  39. const semiLocale = React.useMemo(
  40. () => ({ zh: zh_CN, en: en_GB }[i18n.language] || zh_CN),
  41. [i18n.language],
  42. );
  43. return <LocaleProvider locale={semiLocale}>{children}</LocaleProvider>;
  44. }
  45. // initialization
  46. const root = ReactDOM.createRoot(document.getElementById('root'));
  47. root.render(
  48. <React.StrictMode>
  49. <StatusProvider>
  50. <UserProvider>
  51. <BrowserRouter
  52. future={{
  53. v7_startTransition: true,
  54. v7_relativeSplatPath: true,
  55. }}
  56. >
  57. <ThemeProvider>
  58. <SemiLocaleWrapper>
  59. <PageLayout />
  60. </SemiLocaleWrapper>
  61. </ThemeProvider>
  62. </BrowserRouter>
  63. </UserProvider>
  64. </StatusProvider>
  65. </React.StrictMode>,
  66. );