mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 22:49:26 +08:00
feat: support for switching languages on the login page (#5323)
This commit is contained in:
parent
69ab96afe1
commit
c3e7a8e93b
42
packages/core/client/src/i18n/SwitchLanguage.tsx
Normal file
42
packages/core/client/src/i18n/SwitchLanguage.tsx
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* This file is part of the NocoBase (R) project.
|
||||||
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||||
|
* Authors: NocoBase Team.
|
||||||
|
*
|
||||||
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||||
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TranslationOutlined } from '@ant-design/icons';
|
||||||
|
import { Dropdown } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
import { useAPIClient } from '../api-client';
|
||||||
|
import languageCodes from '../locale';
|
||||||
|
import { useSystemSettings } from '../system-settings';
|
||||||
|
|
||||||
|
export function SwitchLanguage() {
|
||||||
|
const { data } = useSystemSettings();
|
||||||
|
const api = useAPIClient();
|
||||||
|
return (
|
||||||
|
data?.data?.enabledLanguages.length > 1 && (
|
||||||
|
<Dropdown
|
||||||
|
menu={{
|
||||||
|
onClick(info) {
|
||||||
|
api.auth.setLocale(info.key);
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
selectable: true,
|
||||||
|
defaultSelectedKeys: [api.auth.locale],
|
||||||
|
items: data?.data?.enabledLanguages?.map((code) => {
|
||||||
|
return {
|
||||||
|
key: code,
|
||||||
|
label: languageCodes[code].label,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TranslationOutlined style={{ fontSize: 24 }} />
|
||||||
|
</Dropdown>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
@ -73,7 +73,10 @@ export * from './modules/blocks/useParentRecordCommon';
|
|||||||
export { OpenModeProvider, useOpenModeContext } from './modules/popup/OpenModeProvider';
|
export { OpenModeProvider, useOpenModeContext } from './modules/popup/OpenModeProvider';
|
||||||
export { PopupContextProvider } from './modules/popup/PopupContextProvider';
|
export { PopupContextProvider } from './modules/popup/PopupContextProvider';
|
||||||
export { usePopupUtils } from './modules/popup/usePopupUtils';
|
export { usePopupUtils } from './modules/popup/usePopupUtils';
|
||||||
export {
|
|
||||||
VariablePopupRecordProvider,
|
export { SwitchLanguage } from './i18n/SwitchLanguage';
|
||||||
useCurrentPopupRecord,
|
export { VariablePopupRecordProvider } from './modules/variable/variablesProvider/VariablePopupRecordProvider';
|
||||||
} from './modules/variable/variablesProvider/VariablePopupRecordProvider';
|
|
||||||
|
export { useCurrentPopupRecord } from './modules/variable/variablesProvider/VariablePopupRecordProvider';
|
||||||
|
|
||||||
|
export { languageCodes } from './locale';
|
||||||
|
@ -7,6 +7,15 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the NocoBase (R) project.
|
||||||
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||||
|
* Authors: NocoBase Team.
|
||||||
|
*
|
||||||
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||||
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
export type LocaleOptions = {
|
export type LocaleOptions = {
|
||||||
label: string;
|
label: string;
|
||||||
};
|
};
|
||||||
@ -81,7 +90,7 @@ export const dayjsLocale = {
|
|||||||
'zh-TW': 'zh-tw',
|
'zh-TW': 'zh-tw',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export const languageCodes = {
|
||||||
'ar-EG': { label: 'العربية' },
|
'ar-EG': { label: 'العربية' },
|
||||||
'az-AZ': { label: 'Azərbaycan dili' },
|
'az-AZ': { label: 'Azərbaycan dili' },
|
||||||
'bg-BG': { label: 'Български' },
|
'bg-BG': { label: 'Български' },
|
||||||
@ -150,3 +159,5 @@ export default {
|
|||||||
'zh-HK': { label: '繁體中文(香港)' },
|
'zh-HK': { label: '繁體中文(香港)' },
|
||||||
'zh-TW': { label: '繁體中文(台湾)' },
|
'zh-TW': { label: '繁體中文(台湾)' },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default languageCodes;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { PoweredBy, ReadPretty, useAPIClient, useRequest, useSystemSettings } from '@nocobase/client';
|
import { PoweredBy, ReadPretty, SwitchLanguage, useAPIClient, useRequest, useSystemSettings } from '@nocobase/client';
|
||||||
import { Spin } from 'antd';
|
import { Spin } from 'antd';
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { Outlet } from 'react-router-dom';
|
import { Outlet } from 'react-router-dom';
|
||||||
@ -46,7 +46,6 @@ export const AuthenticatorsContextProvider: FC<{ children: React.ReactNode }> =
|
|||||||
|
|
||||||
export function AuthLayout() {
|
export function AuthLayout() {
|
||||||
const { data } = useSystemSettings();
|
const { data } = useSystemSettings();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@ -55,6 +54,9 @@ export function AuthLayout() {
|
|||||||
paddingTop: '20vh',
|
paddingTop: '20vh',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<div style={{ position: 'fixed', top: '2em', right: '2em' }}>
|
||||||
|
<SwitchLanguage />
|
||||||
|
</div>
|
||||||
<h1 style={{ textAlign: 'center' }}>
|
<h1 style={{ textAlign: 'center' }}>
|
||||||
<ReadPretty.TextArea value={data?.data?.title} />
|
<ReadPretty.TextArea value={data?.data?.title} />
|
||||||
</h1>
|
</h1>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user