add language for the request path

This commit is contained in:
huoyo 2023-04-07 16:27:34 +08:00
parent 3abd1b6436
commit 8bb5adb21f
2 changed files with 8 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package cn.langpy.kotime.constant;
import cn.langpy.kotime.util.Context;
import org.springframework.util.StringUtils;
public class KoConstant {
public final static String comMethodRange = "@annotation(cn.langpy.kotime.annotation.ComputeTime)";
@ -14,8 +15,11 @@ public class KoConstant {
public final static String kotimeViewerEn = "kotime-en.html";
public final static String loginName = "kotimeUserName";
public static String getViewName() {
if ("chinese".equals(Context.getConfig().getLanguage())) {
public static String getViewName(String language) {
if (!StringUtils.hasText(language)) {
language = Context.getConfig().getLanguage();
}
if ("chinese".equals(language)) {
return kotimeViewer;
}else {
return kotimeViewerEn;

View File

@ -79,7 +79,7 @@ public class KoTimeController {
@GetMapping
public void index(String kotoken, String test,String charset, HttpServletResponse response, HttpServletRequest request) {
public void index(String kotoken, String test,String charset, String language,HttpServletResponse response, HttpServletRequest request) {
if (!Context.getConfig().getEnable()) {
return;
}
@ -94,7 +94,7 @@ public class KoTimeController {
charset = "utf-8";
}
response.setContentType("text/html;charset="+charset);
ClassPathResource classPathResource = new ClassPathResource(KoConstant.getViewName());
ClassPathResource classPathResource = new ClassPathResource(KoConstant.getViewName(language));
try (
InputStream inputStream = classPathResource.getInputStream();
InputStreamReader streamReader = new InputStreamReader(inputStream, "utf-8");