fix: language settings

This commit is contained in:
chenos 2022-03-21 21:37:35 +08:00
parent 7285dd04ee
commit f7ce3f64cf
5 changed files with 35 additions and 6 deletions

View File

@ -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,

View File

@ -19,7 +19,7 @@ export function AntdConfigProvider(props) {
i18n.changeLanguage(data?.data?.lang);
}
},
manual: true, // !remoteLocale,
manual: !remoteLocale,
},
);
if (loading) {

View File

@ -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,
},
});
},
};

View File

@ -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();
}}

View File

@ -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();
},