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; package cn.langpy.kotime.constant;
import cn.langpy.kotime.util.Context; import cn.langpy.kotime.util.Context;
import org.springframework.util.StringUtils;
public class KoConstant { public class KoConstant {
public final static String comMethodRange = "@annotation(cn.langpy.kotime.annotation.ComputeTime)"; 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 kotimeViewerEn = "kotime-en.html";
public final static String loginName = "kotimeUserName"; public final static String loginName = "kotimeUserName";
public static String getViewName() { public static String getViewName(String language) {
if ("chinese".equals(Context.getConfig().getLanguage())) { if (!StringUtils.hasText(language)) {
language = Context.getConfig().getLanguage();
}
if ("chinese".equals(language)) {
return kotimeViewer; return kotimeViewer;
}else { }else {
return kotimeViewerEn; return kotimeViewerEn;

View File

@ -79,7 +79,7 @@ public class KoTimeController {
@GetMapping @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()) { if (!Context.getConfig().getEnable()) {
return; return;
} }
@ -94,7 +94,7 @@ public class KoTimeController {
charset = "utf-8"; charset = "utf-8";
} }
response.setContentType("text/html;charset="+charset); response.setContentType("text/html;charset="+charset);
ClassPathResource classPathResource = new ClassPathResource(KoConstant.getViewName()); ClassPathResource classPathResource = new ClassPathResource(KoConstant.getViewName(language));
try ( try (
InputStream inputStream = classPathResource.getInputStream(); InputStream inputStream = classPathResource.getInputStream();
InputStreamReader streamReader = new InputStreamReader(inputStream, "utf-8"); InputStreamReader streamReader = new InputStreamReader(inputStream, "utf-8");