fix: language settings
This commit is contained in:
parent
7285dd04ee
commit
f7ce3f64cf
@ -12,6 +12,7 @@ process.env.MFSU_AD = 'none';
|
|||||||
const umiConfig = getUmiConfig();
|
const umiConfig = getUmiConfig();
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
hash: true,
|
||||||
define: {
|
define: {
|
||||||
'process.env.NOCOBASE_ENV': process.env.NOCOBASE_ENV,
|
'process.env.NOCOBASE_ENV': process.env.NOCOBASE_ENV,
|
||||||
...umiConfig.define,
|
...umiConfig.define,
|
||||||
|
@ -19,7 +19,7 @@ export function AntdConfigProvider(props) {
|
|||||||
i18n.changeLanguage(data?.data?.lang);
|
i18n.changeLanguage(data?.data?.lang);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
manual: true, // !remoteLocale,
|
manual: !remoteLocale,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
@ -3,7 +3,15 @@ import { uid } from '@formily/shared';
|
|||||||
import { Menu } from 'antd';
|
import { Menu } from 'antd';
|
||||||
import React, { useContext, useState } from 'react';
|
import React, { useContext, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ActionContext, DropdownVisibleContext, SchemaComponent, useActionContext, useCurrentUserContext, useRequest } from '../';
|
import {
|
||||||
|
ActionContext,
|
||||||
|
DropdownVisibleContext,
|
||||||
|
SchemaComponent,
|
||||||
|
useActionContext,
|
||||||
|
useCurrentUserContext,
|
||||||
|
useRequest
|
||||||
|
} from '../';
|
||||||
|
import { useAPIClient } from '../api-client';
|
||||||
|
|
||||||
const useCloseAction = () => {
|
const useCloseAction = () => {
|
||||||
const { setVisible } = useActionContext();
|
const { setVisible } = useActionContext();
|
||||||
@ -24,13 +32,22 @@ const useCurrentUserValues = (options) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useSaveCurrentUserValues = () => {
|
const useSaveCurrentUserValues = () => {
|
||||||
|
const ctx = useCurrentUserContext();
|
||||||
const { setVisible } = useActionContext();
|
const { setVisible } = useActionContext();
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
|
const api = useAPIClient();
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
form.submit((values) => {
|
const values = await form.submit<any>();
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
console.log(values);
|
await api.resource('users').updateProfile({
|
||||||
|
values,
|
||||||
|
});
|
||||||
|
ctx.mutate({
|
||||||
|
data: {
|
||||||
|
...ctx?.data?.data,
|
||||||
|
...values,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import { Menu, Select } from 'antd';
|
import { Menu, Select } from 'antd';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useAPIClient, useCurrentUserContext } from '..';
|
||||||
|
|
||||||
export const LanguageSettings = () => {
|
export const LanguageSettings = () => {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const api = useAPIClient();
|
||||||
|
const ctx = useCurrentUserContext();
|
||||||
return (
|
return (
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@ -25,6 +28,11 @@ export const LanguageSettings = () => {
|
|||||||
]}
|
]}
|
||||||
value={i18n.language}
|
value={i18n.language}
|
||||||
onChange={async (lang) => {
|
onChange={async (lang) => {
|
||||||
|
await api.resource('users').updateProfile({
|
||||||
|
values: {
|
||||||
|
appLang: lang,
|
||||||
|
},
|
||||||
|
});
|
||||||
await i18n.changeLanguage(lang);
|
await i18n.changeLanguage(lang);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}}
|
}}
|
||||||
|
@ -32,8 +32,11 @@ export class ClientPlugin extends Plugin {
|
|||||||
name: 'app',
|
name: 'app',
|
||||||
actions: {
|
actions: {
|
||||||
async getLang(ctx, next) {
|
async getLang(ctx, next) {
|
||||||
|
const SystemSetting = ctx.db.getRepository('systemSettings');
|
||||||
|
const systemSetting = await SystemSetting.findOne();
|
||||||
|
const currentUser = ctx.state.currentUser;
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
lang: 'zh-CN',
|
lang: currentUser?.appLang || systemSetting?.appLang || process.env.APP_LANG || 'en-US',
|
||||||
};
|
};
|
||||||
await next();
|
await next();
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user