mirror of https://github.com/halo-dev/halo
🎨 支持后台切换语言
parent
55d3f20e4c
commit
a95321a809
|
@ -2,13 +2,19 @@ package cc.ryanc.halo.config;
|
||||||
|
|
||||||
import cc.ryanc.halo.web.interceptor.ApiInterceptor;
|
import cc.ryanc.halo.web.interceptor.ApiInterceptor;
|
||||||
import cc.ryanc.halo.web.interceptor.InstallInterceptor;
|
import cc.ryanc.halo.web.interceptor.InstallInterceptor;
|
||||||
|
import cc.ryanc.halo.web.interceptor.LocaleInterceptor;
|
||||||
import cc.ryanc.halo.web.interceptor.LoginInterceptor;
|
import cc.ryanc.halo.web.interceptor.LoginInterceptor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.web.servlet.LocaleResolver;
|
||||||
import org.springframework.web.servlet.config.annotation.*;
|
import org.springframework.web.servlet.config.annotation.*;
|
||||||
|
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -34,6 +40,9 @@ public class MvcConfig implements WebMvcConfigurer {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiInterceptor apiInterceptor;
|
private ApiInterceptor apiInterceptor;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LocaleInterceptor localeInterceptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册拦截器
|
* 注册拦截器
|
||||||
*
|
*
|
||||||
|
@ -54,6 +63,9 @@ public class MvcConfig implements WebMvcConfigurer {
|
||||||
.excludePathPatterns("/static/**");
|
.excludePathPatterns("/static/**");
|
||||||
registry.addInterceptor(apiInterceptor)
|
registry.addInterceptor(apiInterceptor)
|
||||||
.addPathPatterns("/api/**");
|
.addPathPatterns("/api/**");
|
||||||
|
registry.addInterceptor(localeInterceptor)
|
||||||
|
.addPathPatterns("/admin/**")
|
||||||
|
.addPathPatterns("/install");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,4 +96,11 @@ public class MvcConfig implements WebMvcConfigurer {
|
||||||
.allowedOrigins("*")
|
.allowedOrigins("*")
|
||||||
.allowedMethods("*");
|
.allowedMethods("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LocaleResolver localeResolver() {
|
||||||
|
SessionLocaleResolver slr = new SessionLocaleResolver();
|
||||||
|
slr.setDefaultLocale(Locale.CHINA);
|
||||||
|
return slr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,11 @@ package cc.ryanc.halo.model.enums;
|
||||||
*/
|
*/
|
||||||
public enum BlogPropertiesEnum {
|
public enum BlogPropertiesEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 博客语言
|
||||||
|
*/
|
||||||
|
BLOG_LOCALE("blog_locale"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 博客标题
|
* 博客标题
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package cc.ryanc.halo.model.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : wangry
|
||||||
|
* @version : 1.0
|
||||||
|
* @date : 2018年09月08日
|
||||||
|
*/
|
||||||
|
public enum LocaleEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 简体中文
|
||||||
|
*/
|
||||||
|
ZH_CN("zh_CN"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 英文
|
||||||
|
*/
|
||||||
|
EN_US("en_US");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
LocaleEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -83,6 +83,7 @@ public class InstallController {
|
||||||
/**
|
/**
|
||||||
* 执行安装
|
* 执行安装
|
||||||
*
|
*
|
||||||
|
* @param blogLocale 系统语言
|
||||||
* @param siteTitle 博客标题
|
* @param siteTitle 博客标题
|
||||||
* @param siteUrl 博客网址
|
* @param siteUrl 博客网址
|
||||||
* @param userName 用户名
|
* @param userName 用户名
|
||||||
|
@ -94,7 +95,8 @@ public class InstallController {
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/do")
|
@PostMapping(value = "/do")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public boolean doInstall(@RequestParam("blogTitle") String blogTitle,
|
public boolean doInstall(@RequestParam("blogLocale") String blogLocale,
|
||||||
|
@RequestParam("blogTitle") String blogTitle,
|
||||||
@RequestParam("blogUrl") String blogUrl,
|
@RequestParam("blogUrl") String blogUrl,
|
||||||
@RequestParam("userName") String userName,
|
@RequestParam("userName") String userName,
|
||||||
@RequestParam("userDisplayName") String userDisplayName,
|
@RequestParam("userDisplayName") String userDisplayName,
|
||||||
|
@ -157,6 +159,8 @@ public class InstallController {
|
||||||
|
|
||||||
optionsService.saveOption(BlogPropertiesEnum.IS_INSTALL.getProp(), TrueFalseEnum.TRUE.getDesc());
|
optionsService.saveOption(BlogPropertiesEnum.IS_INSTALL.getProp(), TrueFalseEnum.TRUE.getDesc());
|
||||||
|
|
||||||
|
//语言设置
|
||||||
|
optionsService.saveOption(BlogPropertiesEnum.BLOG_LOCALE.getProp(),blogLocale);
|
||||||
//保存博客标题和博客地址设置
|
//保存博客标题和博客地址设置
|
||||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_TITLE.getProp(), blogTitle);
|
optionsService.saveOption(BlogPropertiesEnum.BLOG_TITLE.getProp(), blogTitle);
|
||||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_URL.getProp(), blogUrl);
|
optionsService.saveOption(BlogPropertiesEnum.BLOG_URL.getProp(), blogUrl);
|
||||||
|
|
|
@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class ApiInterceptor implements HandlerInterceptor {
|
public class ApiInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
if (StringUtils.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.API_STATUS.getProp()))) {
|
if (StringUtils.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.API_STATUS.getProp()))) {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package cc.ryanc.halo.web.interceptor;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
|
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||||
|
import cc.ryanc.halo.model.enums.LocaleEnum;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : wangry
|
||||||
|
* @version : 1.0
|
||||||
|
* @date : 2018年09月08日
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class LocaleInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
if (StringUtils.equals(LocaleEnum.EN_US.getValue(), HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_LOCALE.getProp()))) {
|
||||||
|
request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("en", "US"));
|
||||||
|
} else {
|
||||||
|
request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("zh", "CN"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class LoginInterceptor implements HandlerInterceptor {
|
public class LoginInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
Object obj = request.getSession().getAttribute(HaloConst.USER_SESSION_KEY);
|
Object obj = request.getSession().getAttribute(HaloConst.USER_SESSION_KEY);
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
# 安装页面
|
# 安装页面
|
||||||
install.page.title = 安装向导
|
install.page.title = 安装向导
|
||||||
install.form.blogTitle = 博客标题
|
install.form.language = 系统语言:
|
||||||
install.form.blogUrl = 博客地址
|
install.form.blogTitle = 博客标题:
|
||||||
install.form.userEmail = 电子邮箱
|
install.form.blogUrl = 博客地址:
|
||||||
install.form.userName = 用户名
|
install.form.userEmail = 电子邮箱:
|
||||||
install.form.userDisplayName = 显示昵称
|
install.form.userName = 用户名:
|
||||||
install.form.userPwd = 登录密码
|
install.form.userDisplayName = 显示昵称:
|
||||||
install.form.userRePwd = 确认密码
|
install.form.userPwd = 登录密码:
|
||||||
|
install.form.userRePwd = 确认密码:
|
||||||
install.btn.submit = 安装Halo
|
install.btn.submit = 安装Halo
|
||||||
install.success.title = 安装成功!
|
install.success.title = 安装成功!
|
||||||
install.success.message = 你可以选择进入前台,或者登陆后台!
|
install.success.message = 你可以选择进入前台,或者登陆后台!
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
# install page
|
# install page
|
||||||
install.page.title = Installation Guide
|
install.page.title = Installation Guide
|
||||||
install.form.blogTitle = Blog title
|
install.form.language = Language:
|
||||||
install.form.blogUrl = Blog address
|
install.form.blogTitle = Blog title:
|
||||||
install.form.userEmail = Email
|
install.form.blogUrl = Blog address:
|
||||||
install.form.userName = Username
|
install.form.userEmail = Email:
|
||||||
install.form.userDisplayName = Display nickname
|
install.form.userName = Username:
|
||||||
install.form.userPwd = Password
|
install.form.userDisplayName = Display nickname:
|
||||||
install.form.userRePwd = Confirm password
|
install.form.userPwd = Password:
|
||||||
|
install.form.userRePwd = Confirm password:
|
||||||
install.btn.submit = Install
|
install.btn.submit = Install
|
||||||
install.success.title = Installation successful!
|
install.success.title = Installation successful!
|
||||||
install.success.message = You can choose to go to the homepage or log in to the dashboard!
|
install.success.message = You can choose to go to the homepage or log in to the dashboard!
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
# 安装页面
|
# 安装页面
|
||||||
install.page.title = 安装向导
|
install.page.title = 安装向导
|
||||||
install.form.blogTitle = 博客标题
|
install.form.language = 系统语言:
|
||||||
install.form.blogUrl = 博客地址
|
install.form.blogTitle = 博客标题:
|
||||||
install.form.userEmail = 电子邮箱
|
install.form.blogUrl = 博客地址:
|
||||||
install.form.userName = 用户名
|
install.form.userEmail = 电子邮箱:
|
||||||
install.form.userDisplayName = 显示昵称
|
install.form.userName = 用户名:
|
||||||
install.form.userPwd = 登录密码
|
install.form.userDisplayName = 显示昵称:
|
||||||
install.form.userRePwd = 确认密码
|
install.form.userPwd = 登录密码:
|
||||||
|
install.form.userRePwd = 确认密码:
|
||||||
install.btn.submit = 安装Halo
|
install.btn.submit = 安装Halo
|
||||||
install.success.title = 安装成功!
|
install.success.title = 安装成功!
|
||||||
install.success.message = 你可以选择进入前台,或者登陆后台!
|
install.success.message = 你可以选择进入前台,或者登陆后台!
|
||||||
|
|
|
@ -65,6 +65,15 @@
|
||||||
<div class="tab-pane active" id="general">
|
<div class="tab-pane active" id="general">
|
||||||
<form method="post" class="form-horizontal" id="commonOptions">
|
<form method="post" class="form-horizontal" id="commonOptions">
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="blogLocale" class="col-lg-2 col-sm-4 control-label">系统语言:</label>
|
||||||
|
<div class="col-lg-4 col-sm-8">
|
||||||
|
<select class="form-control" id="blogLocale" name="blog_locale">
|
||||||
|
<option value="zh_CN" ${((options.blog_locale?default('zh_CN'))=='zh_CN')?string('selected','')}>简体中文</option>
|
||||||
|
<option value="en_US" ${((options.blog_locale?if_exists)=='en_US')?string('selected','')}>English</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="blogTitle" class="col-lg-2 col-sm-4 control-label">博客标题:</label>
|
<label for="blogTitle" class="col-lg-2 col-sm-4 control-label">博客标题:</label>
|
||||||
<div class="col-lg-4 col-sm-8">
|
<div class="col-lg-4 col-sm-8">
|
||||||
|
|
|
@ -39,50 +39,59 @@
|
||||||
<div class="box box-solid animated" id="installFirst">
|
<div class="box box-solid animated" id="installFirst">
|
||||||
<div class="box-body" style="padding: 30px;">
|
<div class="box-body" style="padding: 30px;">
|
||||||
<div class="form-group animated fadeInUp" style="animation-delay: 0.1s">
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.1s">
|
||||||
<label for="blogTitle" class="col-sm-4 control-label"><@spring.message code='install.form.blogTitle'/>:</label>
|
<label for="blogLocale" class="col-sm-4 control-label"><@spring.message code='install.form.language'/></label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<select class="form-control" id="blogLocale" name="blogLocale">
|
||||||
|
<option value="zh_CN" ${((options.blog_locale?default('zh_CN'))=='zh_CN')?string('selected','')}>简体中文</option>
|
||||||
|
<option value="en_US" ${((options.blog_locale?if_exists)=='en_US')?string('selected','')}>English</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.2s">
|
||||||
|
<label for="blogTitle" class="col-sm-4 control-label"><@spring.message code='install.form.blogTitle'/></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="text" class="form-control" id="blogTitle" name="blogTitle">
|
<input type="text" class="form-control" id="blogTitle" name="blogTitle">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group animated fadeInUp" style="animation-delay: 0.1s">
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.3s">
|
||||||
<label for="blogUrl" class="col-sm-4 control-label"><@spring.message code='install.form.blogUrl'/>:</label>
|
<label for="blogUrl" class="col-sm-4 control-label"><@spring.message code='install.form.blogUrl'/></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="text" class="form-control" id="blogUrl" name="blogUrl">
|
<input type="text" class="form-control" id="blogUrl" name="blogUrl">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group animated fadeInUp" style="animation-delay: 0.2s">
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.4s">
|
||||||
<label for="userEmail" class="col-sm-4 control-label"><@spring.message code='install.form.userEmail'/>:</label>
|
<label for="userEmail" class="col-sm-4 control-label"><@spring.message code='install.form.userEmail'/></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="text" class="form-control" id="userEmail" name="userEmail">
|
<input type="text" class="form-control" id="userEmail" name="userEmail">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group animated fadeInUp" style="animation-delay: 0.3s">
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.5s">
|
||||||
<label for="userName" class="col-sm-4 control-label"><@spring.message code='install.form.userName'/>:</label>
|
<label for="userName" class="col-sm-4 control-label"><@spring.message code='install.form.userName'/></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="text" class="form-control" id="userName" name="userName">
|
<input type="text" class="form-control" id="userName" name="userName">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group animated fadeInUp" style="animation-delay: 0.4s">
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.6s">
|
||||||
<label for="userDisplayName" class="col-sm-4 control-label"><@spring.message code='install.form.userDisplayName'/>:</label>
|
<label for="userDisplayName" class="col-sm-4 control-label"><@spring.message code='install.form.userDisplayName'/></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="text" class="form-control" id="userDisplayName" name="userDisplayName">
|
<input type="text" class="form-control" id="userDisplayName" name="userDisplayName">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group animated fadeInUp" style="animation-delay: 0.5s">
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.7s">
|
||||||
<label for="userPwd" class="col-sm-4 control-label"><@spring.message code='install.form.userPwd'/>:</label>
|
<label for="userPwd" class="col-sm-4 control-label"><@spring.message code='install.form.userPwd'/></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="password" class="form-control" id="userPwd" name="userPwd">
|
<input type="password" class="form-control" id="userPwd" name="userPwd">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group animated fadeInUp" style="animation-delay: 0.6s">
|
<div class="form-group animated fadeInUp" style="animation-delay: 0.8s">
|
||||||
<label for="userRePwd" class="col-sm-4 control-label"><@spring.message code='install.form.userRePwd'/>:</label>
|
<label for="userRePwd" class="col-sm-4 control-label"><@spring.message code='install.form.userRePwd'/></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="password" class="form-control" id="userRePwd" name="userRePwd">
|
<input type="password" class="form-control" id="userRePwd" name="userRePwd">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-footer" style="padding-right: 30px;">
|
<div class="box-footer" style="padding-right: 30px;">
|
||||||
<button type="submit" class="btn btn-primary btn-sm btn-flat pull-right animated fadeInUp" style="animation-delay: 0.9s"><@spring.message code='install.btn.submit'/></button>
|
<button type="submit" class="btn btn-primary btn-sm btn-flat pull-right animated fadeInUp" style="animation-delay: 1s"><@spring.message code='install.btn.submit'/></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box box-solid animated fadeInUp" style="display: none" id="installSuccess">
|
<div class="box box-solid animated fadeInUp" style="display: none" id="installSuccess">
|
||||||
|
|
Loading…
Reference in New Issue