Unverified Commit ff7618f1 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Fix][admin] Fix backend internationalization (#1260)

* upgrade i18n messages * [Optimize][web] optimize check tenant * [Feature][admin] Add backend internationalization messages * fix encoding * fix backend i18n check error * upgrade i18n messages
parent 4cb57f87
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package com.dlink.configure; package com.dlink.configure;
import com.dlink.constant.BaseConstant;
import com.dlink.interceptor.LocaleChangeInterceptor;
import com.dlink.interceptor.TenantInterceptor; import com.dlink.interceptor.TenantInterceptor;
import java.util.Locale; import java.util.Locale;
...@@ -29,7 +31,6 @@ import org.springframework.web.servlet.LocaleResolver; ...@@ -29,7 +31,6 @@ import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.CookieLocaleResolver; import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import cn.dev33.satoken.interceptor.SaRouteInterceptor; import cn.dev33.satoken.interceptor.SaRouteInterceptor;
...@@ -42,8 +43,6 @@ import cn.dev33.satoken.interceptor.SaRouteInterceptor; ...@@ -42,8 +43,6 @@ import cn.dev33.satoken.interceptor.SaRouteInterceptor;
@Configuration @Configuration
public class AppConfiguration implements WebMvcConfigurer { public class AppConfiguration implements WebMvcConfigurer {
public static final String LOCALE_LANGUAGE_COOKIE = "language";
/** /**
* Cookie * Cookie
* *
...@@ -52,7 +51,7 @@ public class AppConfiguration implements WebMvcConfigurer { ...@@ -52,7 +51,7 @@ public class AppConfiguration implements WebMvcConfigurer {
@Bean(name = "localeResolver") @Bean(name = "localeResolver")
public LocaleResolver localeResolver() { public LocaleResolver localeResolver() {
CookieLocaleResolver localeResolver = new CookieLocaleResolver(); CookieLocaleResolver localeResolver = new CookieLocaleResolver();
localeResolver.setCookieName(LOCALE_LANGUAGE_COOKIE); localeResolver.setCookieName(BaseConstant.LOCALE_LANGUAGE_COOKIE);
// set default locale // set default locale
localeResolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE); localeResolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
// set language tag compliant // set language tag compliant
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.dlink.constant;
public class BaseConstant {
public static final String LOCALE_LANGUAGE_COOKIE = "language";
}
...@@ -68,7 +68,7 @@ public class WebExceptionHandler { ...@@ -68,7 +68,7 @@ public class WebExceptionHandler {
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = servletRequestAttributes.getResponse(); HttpServletResponse response = servletRequestAttributes.getResponse();
response.setStatus(CodeEnum.NOTLOGIN.getCode()); response.setStatus(CodeEnum.NOTLOGIN.getCode());
return Result.notLogin(MessageResolverUtils.getMessage("login.not-login")); return Result.notLogin(MessageResolverUtils.getMessage("login.not.login"));
} }
@ResponseStatus(HttpStatus.BAD_REQUEST) // 设置状态码为 400 @ResponseStatus(HttpStatus.BAD_REQUEST) // 设置状态码为 400
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dlink.interceptor;
import com.dlink.assertion.Asserts;
import com.dlink.constant.BaseConstant;
import java.util.Locale;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.util.WebUtils;
public class LocaleChangeInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
Cookie cookie = WebUtils.getCookie(request, BaseConstant.LOCALE_LANGUAGE_COOKIE);
if (Asserts.isNotNull(cookie)) {
// Proceed in cookie
return true;
}
// Proceed in header
String newLocale = request.getHeader(BaseConstant.LOCALE_LANGUAGE_COOKIE);
if (Asserts.isNotNull(newLocale)) {
LocaleContextHolder.setLocale(parseLocaleValue(newLocale));
}
return true;
}
@Nullable
protected Locale parseLocaleValue(String localeValue) {
return StringUtils.parseLocale(localeValue);
}
}
...@@ -242,7 +242,7 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen ...@@ -242,7 +242,7 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
Set<Integer> tenantIds = new HashSet<>(); Set<Integer> tenantIds = new HashSet<>();
userTenants.forEach(userTenant -> tenantIds.add(userTenant.getTenantId())); userTenants.forEach(userTenant -> tenantIds.add(userTenant.getTenantId()));
List<Tenant> tenants = tenantService.getTenantByIds(tenantIds); List<Tenant> tenants = tenantService.getTenantByIds(tenantIds);
return Result.succeed(tenants, MessageResolverUtils.getMessage("response.get.successfully")); return Result.succeed(tenants, MessageResolverUtils.getMessage("response.get.success"));
} }
} }
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.dlink.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 给指定类型文件,增加版权信息
* dir: 文件夹(会递归获取该文件夹下符合 @fileEndWithStr 的目标文件)
* fileEndWithStr: 文件类型后缀
* copyright : 版权信息 Apache LICENSE-2.0
*/
public class CopyrightUtil {
private static Logger log = LoggerFactory.getLogger(CopyrightUtil.class);
public static String dir = "d:\\your-dir";
public static String fileEndWithStr = ".less";
public static String copyright = "/*\n"
+ " *\n"
+ " * Licensed to the Apache Software Foundation (ASF) under one or more\n"
+ " * contributor license agreements. See the NOTICE file distributed with\n"
+ " * this work for additional information regarding copyright ownership.\n"
+ " * The ASF licenses this file to You under the Apache License, Version 2.0\n"
+ " * (the \"License\"); you may not use this file except in compliance with\n"
+ " * the License. You may obtain a copy of the License at\n"
+ " *\n"
+ " * http://www.apache.org/licenses/LICENSE-2.0\n"
+ " *\n"
+ " * Unless required by applicable law or agreed to in writing, software\n"
+ " * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
+ " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
+ " * See the License for the specific language governing permissions and\n"
+ " * limitations under the License.\n"
+ " *\n"
+ " */\n\n\n";
public static void main(String[] args) throws Exception {
//java文件所在目录
File file = new File(dir);
addCopyright4Directory(file);
}
public static void addCopyright4Directory(File file) throws Exception {
File[] files = file.listFiles();
if (files == null || files.length == 0) {
return;
}
for (File f : files) {
if (f.isFile()) {
addCopyright4File(f);
log.info("文件==={}", f.getName());
} else {
log.info("目录=={}", f.getName());
addCopyright4Directory(f);
}
}
}
public static void addCopyright4File(File file) throws Exception {
String fileName = file.getName();
boolean endWith = fileName.endsWith(fileEndWithStr);
if (!endWith) {
log.info("This file is not " + fileEndWithStr + " source file,filaName=" + fileName);
return;
}
if (endWith) {
// 版权字符串
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
String content = "";
String lineSeperator = "\n";
while ((line = br.readLine()) != null) {
content += line + lineSeperator;
}
br.close();
//把拼接后的字符串写回去
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(copyright);
fileWriter.write(content);
fileWriter.close();
}
}
}
\ No newline at end of file
...@@ -18,23 +18,37 @@ ...@@ -18,23 +18,37 @@
unknown.i18n=未知的国际化信息,请检查。。。 unknown.i18n=未知的国际化信息,请检查。。。
modify.successfully=修改成功 # base crud messages
modify.success=修改成功
modify.failed=修改失败 modify.failed=修改失败
delete.successfully=修改成功 delete.success=删除成功
delete.failed=修改失败 delete.failed=删除失败
delete.partially.successfully=删除部分成功,但 {0} 删除失败,共 {1} 次失败。 delete.partially.success=删除部分成功,但 {0} 删除失败,共 {1} 次失败。
delete.placeholder=请选择要删除的记录
response.get.successfully=获取成功 create.success=新增成功
response.get.failed=获取失败 create.failed=新增失败
# response messages
request.params.error=请求参数错误 request.params.error=请求参数错误
response.get.success=获取成功
response.get.failed=获取失败
response.send.success=发送成功
response.send.failed=发送失败
response.execute.success=执行成功
response.execute.failed=执行失败
response.restart.success=重启成功
response.restart.failed=重启失败
response.test.connect.success=测试链接成功
response.test.connect.failed=测试链接失败
# validation messages
error.param.empty={0}不能为空 error.param.empty={0}不能为空
error.param.invalid={0}无效 error.param.invalid={0}无效
error.param.occupied={0}已被占用 error.param.occupied={0}已被占用
# login messages
login.fail=登录失败,用户名或密码错误 login.fail=登录失败,用户名或密码错误
login.not-login=用户未登录,请先登录 login.not.login=用户未登录,请先登录
login.session.timeout=会话已过期,请重新登录。 login.session.timeout=会话已过期,请重新登录。
login.success=登录成功 login.success=登录成功
login.password.notnull=密码不能为空 login.password.notnull=密码不能为空
...@@ -42,21 +56,25 @@ login.user.not.exists=账号不存在 ...@@ -42,21 +56,25 @@ login.user.not.exists=账号不存在
login.user.disabled=账号已被禁用 login.user.disabled=账号已被禁用
outlogin.success=退出成功 outlogin.success=退出成功
# user messages
user.oldpassword.incorrect=旧密码不正确 user.oldpassword.incorrect=旧密码不正确
user.change.password.success=密码修改成功 user.change.password.success=密码修改成功
user.change.password.failed=密码修改失败 user.change.password.failed=密码修改失败
user.register.account.exists=该账户已存在 user.register.account.exists=该账户已存在
user.register.success=注册成功 user.register.success=注册成功
message.welcome=欢迎使用 Dinky message.welcome=欢迎使用 Dinky
message.task.running=任务已在运行 message.task.running=任务已在运行
base.not.exists={0} 不存在 base.not.exists={0} 不存在
message.provider.config.error=数据源配置解析异常
config.template.jdbc.dbType=数据库类型 task.project.exists=工程已存在
config.template.jdbc.url=连接地址 task.project.upload.success=上传zip包并创建工程成功
config.template.jdbc.user=用户 task.delete.partially.success=删除失败,请检查作业 {0} 状态。
config.template.jdbc.password=密码 task.move.success=移动成功
config.template.jdbc.driverClass=驱动类 task.move.failed=移动失败
config.template.http.schemas=表 task.copy.success=复制作业成功
config.template.http.tableName=表名 task.copy.failed=复制作业失败
...@@ -16,46 +16,63 @@ ...@@ -16,46 +16,63 @@
# #
# #
unknown.i18n=Unknown internationalization information, please check. . . unknown.i18n=Unknown i18n information, please check. . .
modify.successfully=Modified successfully # base crud messages
modify.success=Modify successfully
modify.failed=Modification failed modify.failed=Modification failed
delete.successfully=Modified successfully delete.success=Delete successfully
delete.failed=Modification failed delete.failed=Delete failed
delete.partially.successfully=Delete partially succeeded, but failed to delete {0}, a total of {1} failures. delete.partially.success=Delete was partially successful, but {0} failed to delete out of {1} failures.
delete.placeholder=Please select the record to delete
create.success=Add successfully
create.failed=Create failed
response.get.successfully=Get successfully # response messages
request.params.error=Request parameter error
response.get.success = Get success
response.get.failed=Get failed response.get.failed=Get failed
response.send.success=Send successfully
response.send.failed=Send failed
response.execute.success=Execute successfully
response.execute.failed=Execution failed
response.restart.success=Restart succeeded
response.restart.failed=Restart failed
response.test.connect.success=Test connection successful
response.test.connect.failed=Test connection failed
request.params.error=Request parameters error # validation messages
error.param.empty={0} cannot be empty error.param.empty={0} cannot be empty
error.param.invalid={0} is invalid error.param.invalid={0} is invalid
error.param.occupied={0} is occupied error.param.occupied={0} is already occupied
login.fail=Login failed, wrong username or password # login messages
login.not-login=User is not logged in, please login first login.fail=Login failed, username or password is wrong
login.session.timeout=The session has expired, please log in again. login.not.login=The user is not logged in, please log in first
login.session.timeout=Session has expired, please log in again.
login.success=Login successful login.success=Login successful
login.password.notnull=Password cannot be null login.password.notnull=Password cannot be null
login.user.not.exists=Account does not exist login.user.not.exists=Account does not exist
login.user.disabled=Account is disabled login.user.disabled=Account has been disabled
outlogin.success=Exit successfully outlogin.success=Exit successfully
# user messages
user.oldpassword.incorrect=The old password is incorrect user.oldpassword.incorrect=The old password is incorrect
user.change.password.success=Password changed successfully user.change.password.success=Password changed successfully
user.change.password.failed=Password change failed user.change.password.failed=Password change failed
user.register.account.exists=This account already exists user.register.account.exists=The account already exists
user.register.success=Registration succeeded user.register.success = Registered successfully
message.welcome=Welcome to Dinky message.welcome=Welcome to Dinky
message.task.running=Task is already running message.task.running=Task is already running
base.not.exists={0} does not exist base.not.exists={0} does not exist
message.provider.config.error=Data source configuration parsing exception
config.template.jdbc.dbType=Database Type task.project.exists=Project already exists
config.template.jdbc.url=Connection address task.project.upload.success=Upload zip package and create project successfully
config.template.jdbc.user=User task.delete.partially.success=Delete failed, please check job {0} status.
config.template.jdbc.password=Password task.move.success=Move successfully
config.template.jdbc.driverClass=Driver Class task.move.failed=Move failed
config.template.http.schemas=Table task.copy.success=Copy job succeeded
config.template.http.tableName=Table Name task.copy.failed = Copy job failed
\ No newline at end of file \ No newline at end of file
...@@ -18,23 +18,37 @@ ...@@ -18,23 +18,37 @@
unknown.i18n=未知的国际化信息,请检查。。。 unknown.i18n=未知的国际化信息,请检查。。。
modify.successfully=修改成功 # base crud messages
modify.success=修改成功
modify.failed=修改失败 modify.failed=修改失败
delete.successfully=修改成功 delete.success=删除成功
delete.failed=修改失败 delete.failed=删除失败
delete.partially.successfully=删除部分成功,但 {0} 删除失败,共 {1} 次失败。 delete.partially.success=删除部分成功,但 {0} 删除失败,共 {1} 次失败。
delete.placeholder=请选择要删除的记录
response.get.successfully=获取成功 create.success=新增成功
response.get.failed=获取失败 create.failed=新增失败
# response messages
request.params.error=请求参数错误 request.params.error=请求参数错误
response.get.success=获取成功
response.get.failed=获取失败
response.send.success=发送成功
response.send.failed=发送失败
response.execute.success=执行成功
response.execute.failed=执行失败
response.restart.success=重启成功
response.restart.failed=重启失败
response.test.connect.success=测试链接成功
response.test.connect.failed=测试链接失败
# validation messages
error.param.empty={0}不能为空 error.param.empty={0}不能为空
error.param.invalid={0}无效 error.param.invalid={0}无效
error.param.occupied={0}已被占用 error.param.occupied={0}已被占用
# login messages
login.fail=登录失败,用户名或密码错误 login.fail=登录失败,用户名或密码错误
login.not-login=用户未登录,请先登录 login.not.login=用户未登录,请先登录
login.session.timeout=会话已过期,请重新登录。 login.session.timeout=会话已过期,请重新登录。
login.success=登录成功 login.success=登录成功
login.password.notnull=密码不能为空 login.password.notnull=密码不能为空
...@@ -42,20 +56,25 @@ login.user.not.exists=账号不存在 ...@@ -42,20 +56,25 @@ login.user.not.exists=账号不存在
login.user.disabled=账号已被禁用 login.user.disabled=账号已被禁用
outlogin.success=退出成功 outlogin.success=退出成功
# user messages
user.oldpassword.incorrect=旧密码不正确 user.oldpassword.incorrect=旧密码不正确
user.change.password.success=密码修改成功 user.change.password.success=密码修改成功
user.change.password.failed=密码修改失败 user.change.password.failed=密码修改失败
user.register.account.exists=该账户已存在 user.register.account.exists=该账户已存在
user.register.success=注册成功 user.register.success=注册成功
message.welcome=欢迎使用 Dinky message.welcome=欢迎使用 Dinky
message.task.running=任务已在运行 message.task.running=任务已在运行
base.not.exists={0} 不存在 base.not.exists={0} 不存在
message.provider.config.error=数据源配置解析异常
config.template.jdbc.dbType=数据库类型 task.project.exists=工程已存在
config.template.jdbc.url=连接地址 task.project.upload.success=上传zip包并创建工程成功
config.template.jdbc.user=用户 task.delete.partially.success=删除失败,请检查作业 {0} 状态。
config.template.jdbc.password=密码 task.move.success=移动成功
config.template.jdbc.driverClass=驱动类 task.move.failed=移动失败
config.template.http.schemas=表 task.copy.success=复制作业成功
config.template.http.tableName=表名 task.copy.failed=复制作业失败
\ No newline at end of file
...@@ -51,7 +51,6 @@ const Login: React.FC = () => { ...@@ -51,7 +51,6 @@ const Login: React.FC = () => {
const {initialState, setInitialState} = useModel('@@initialState'); const {initialState, setInitialState} = useModel('@@initialState');
const [isLogin, setIsLogin] = useState<boolean>(true); const [isLogin, setIsLogin] = useState<boolean>(true);
const [chooseTenant, setChooseTenant] = useState<boolean>(false); const [chooseTenant, setChooseTenant] = useState<boolean>(false);
const [tenantId, setTenantId] = useState<number>();
const [tenant, setTenant] = useState<TenantTableListItem[]>([]); const [tenant, setTenant] = useState<TenantTableListItem[]>([]);
const [checkDisabled, setCheckDisabled] = useState<boolean>(true); const [checkDisabled, setCheckDisabled] = useState<boolean>(true);
...@@ -128,8 +127,6 @@ const Login: React.FC = () => { ...@@ -128,8 +127,6 @@ const Login: React.FC = () => {
</Button>, </Button>,
<Button disabled={checkDisabled} type="primary" key="submit" loading={submitting} <Button disabled={checkDisabled} type="primary" key="submit" loading={submitting}
onClick={async () => { onClick={async () => {
userParamsState.tenantId = tenantId;
localStorage.setItem("dlink-tenantId", tenantId.toString());
await handleSubmit(userParamsState); await handleSubmit(userParamsState);
}}> }}>
{l('button.confirm')} {l('button.confirm')}
...@@ -139,9 +136,10 @@ const Login: React.FC = () => { ...@@ -139,9 +136,10 @@ const Login: React.FC = () => {
multiple={false} multiple={false}
onChange={(value) => { onChange={(value) => {
if (value) { if (value) {
setCheckDisabled(false) setCheckDisabled(false) // 如果没选择租户 ·确认按钮· 则禁用
setTenantId(value as number) userParamsState.tenantId = value as number; // 将租户id给后端入参
userParamsState.tenantId = value as number; localStorage.setItem("dlink-tenantId", value.toString()); // 放入本地存储中 request2请求时会放入header
cookies.set('tenantId', value.toString(), {path: '/'}) // 放入cookie中
} else { } else {
setCheckDisabled(true) setCheckDisabled(true)
} }
...@@ -168,6 +166,9 @@ const Login: React.FC = () => { ...@@ -168,6 +166,9 @@ const Login: React.FC = () => {
<div className={styles.container}> <div className={styles.container}>
<div className={styles.lang}>{SelectLang && <SelectLang onItemClick={(e) => { <div className={styles.lang}>{SelectLang && <SelectLang onItemClick={(e) => {
let language = e.key.toString() let language = e.key.toString()
if (language === undefined || language === ""){
language="zh-CN"
}
cookies.set('language', language, {path: '/'}) cookies.set('language', language, {path: '/'})
setLocale(language) setLocale(language)
}}/>}</div> }}/>}</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment