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