🎨 翻译部分页面

pull/33/merge
ruibaby 2018-09-10 22:29:24 +08:00
parent cae1a8e6a8
commit bd09397edb
10 changed files with 185 additions and 43 deletions

View File

@ -0,0 +1,56 @@
package cc.ryanc.halo.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Locale;
/**
* <pre>
*
* </pre>
*
* @author : RYAN0UP
* @date : 2018/9/10
*/
@Component
public class LocaleMessageUtil {
@Autowired
private MessageSource messageSource;
public String getMessage(String code){
return this.getMessage(code,new Object[]{});
}
public String getMessage(String code,String defaultMessage){
return this.getMessage(code,null,defaultMessage);
}
public String getMessage(String code, String defaultMessage, Locale locale){
return this.getMessage(code,null,defaultMessage,locale);
}
public String getMessage(String code,Locale locale){
return this.getMessage(code,null,"",locale);
}
public String getMessage(String code,Object[] args){
return this.getMessage(code,args,"");
}
public String getMessage(String code,Object[] args,Locale locale){
return this.getMessage(code,args,"",locale);
}
public String getMessage(String code,Object[] args,String defaultMessage){
Locale locale = LocaleContextHolder.getLocale();
return this.getMessage(code,args, defaultMessage,locale);
}
public String getMessage(String code,Object[]args,String defaultMessage,Locale locale){
return messageSource.getMessage(code,args, defaultMessage,locale);
}
}

View File

@ -11,6 +11,7 @@ import cc.ryanc.halo.model.enums.CommonParamsEnum;
import cc.ryanc.halo.model.enums.ResultCodeEnum;
import cc.ryanc.halo.model.enums.TrueFalseEnum;
import cc.ryanc.halo.service.*;
import cc.ryanc.halo.utils.LocaleMessageUtil;
import cc.ryanc.halo.web.controller.core.BaseController;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
@ -66,6 +67,9 @@ public class AdminController extends BaseController {
@Autowired
private AttachmentService attachmentService;
@Autowired
private LocaleMessageUtil localeMessageUtil;
/**
*
*
@ -139,7 +143,7 @@ public class AdminController extends BaseController {
}
Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
if (StringUtils.equals(aUser.getLoginEnable(), TrueFalseEnum.FALSE.getDesc()) && (between < CommonParamsEnum.TEN.getValue())) {
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "已禁止登录请10分钟后再试");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.disabled"));
}
//验证用户名和密码
User user = null;
@ -156,7 +160,7 @@ public class AdminController extends BaseController {
userService.updateUserNormal();
logsService.saveByLogs(new Logs(LogsRecord.LOGIN, LogsRecord.LOGIN_SUCCESS, ServletUtil.getClientIP(request), DateUtil.date()));
log.info("用户[{}]登录成功。", aUser.getUserDisplayName());
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "登录成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.login.success"));
} else {
//更新失败次数
Integer errorCount = userService.updateUserLoginError();
@ -172,7 +176,8 @@ public class AdminController extends BaseController {
DateUtil.date()
)
);
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "登录失败,你还有" + (5 - errorCount) + "次机会。");
Object[] args = {(5 - errorCount)};
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.failed", args));
}
}

View File

@ -9,6 +9,7 @@ import cc.ryanc.halo.model.enums.ResultCodeEnum;
import cc.ryanc.halo.service.AttachmentService;
import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.utils.LocaleMessageUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.servlet.ServletUtil;
import lombok.extern.slf4j.Slf4j;
@ -52,6 +53,9 @@ public class AttachmentController {
@Autowired
private LogsService logsService;
@Autowired
private LocaleMessageUtil localeMessageUtil;
/**
* upload
*
@ -168,12 +172,12 @@ public class AttachmentController {
);
result.put("success", 1);
result.put("message", "上传成功!");
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-success"));
result.put("url", attachment.getAttachPath());
} catch (Exception e) {
log.error("上传文件失败:{}", e.getMessage());
result.put("success", 0);
result.put("message", "上传失败!");
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
}
} else {
log.error("文件不能为空");
@ -225,13 +229,13 @@ public class AttachmentController {
);
} else {
log.error("删除附件[{}]失败!", delFileName);
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "删除失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
}
}
} catch (Exception e) {
log.error("删除附件[{}]失败:{}", delFileName, e.getMessage());
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "删除失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
}
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "删除成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-success"));
}
}

View File

@ -9,6 +9,7 @@ import cc.ryanc.halo.model.enums.*;
import cc.ryanc.halo.service.MailService;
import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.utils.LocaleMessageUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
@ -49,6 +50,9 @@ public class BackupController {
@Autowired
private MailService mailService;
@Autowired
private LocaleMessageUtil localeMessageUtil;
/**
*
@ -89,7 +93,7 @@ public class BackupController {
} else if (StringUtils.equals(BackupTypeEnum.POSTS.getDesc(), type)) {
return this.backupPosts();
} else {
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "备份失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
}
}
@ -108,10 +112,10 @@ public class BackupController {
//压缩文件
ZipUtil.zip(srcPath + "halo.mv.db", System.getProperties().getProperty("user.home") + "/halo/backup/databases/" + distName + ".zip");
log.info("当前时间:{},执行了数据库备份。", DateUtil.now());
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "备份成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
} catch (Exception e) {
log.error("备份数据库失败:{}", e.getMessage());
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "备份失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
}
}
@ -131,10 +135,10 @@ public class BackupController {
//执行打包
ZipUtil.zip(srcPath, System.getProperties().getProperty("user.home") + "/halo/backup/resources/" + distName + ".zip");
log.info("当前时间:{},执行了资源文件备份。", DateUtil.now());
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "备份成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
} catch (Exception e) {
log.error("备份资源文件失败:{}", e.getMessage());
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "备份失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
}
}
@ -160,10 +164,10 @@ public class BackupController {
ZipUtil.zip(srcPath, srcPath + ".zip");
FileUtil.del(srcPath);
log.info("当前时间:{},执行了文章备份。", DateUtil.now());
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "备份成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-success"));
} catch (Exception e) {
log.error("备份文章失败:{}", e.getMessage());
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "备份失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed"));
}
}
@ -181,9 +185,9 @@ public class BackupController {
String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
try {
FileUtil.del(srcPath);
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "删除成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-success"));
} catch (Exception e) {
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "删除失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
}
}
@ -202,13 +206,13 @@ public class BackupController {
String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
if (null == user.getUserEmail() || StringUtils.equals(user.getUserEmail(), "")) {
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "博主邮箱没有配置!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.no-email"));
}
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.FALSE.getDesc())) {
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "发信邮箱没有配置!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.no-post"));
}
new EmailToAdmin(srcPath, user).start();
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "邮件发送成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.backup.email-success"));
}
/**
@ -231,7 +235,7 @@ public class BackupController {
content.put("fileName", file.getName());
content.put("createAt", HaloUtils.getCreateTime(srcPath));
content.put("size", HaloUtils.parseSize(file.length()));
mailService.sendAttachMail(user.getUserEmail(), "有新的备份!", content, "common/mail_template/mail_attach.ftl", srcPath);
mailService.sendAttachMail(user.getUserEmail(), localeMessageUtil.getMessage("code.admin.backup.have-new-backup"), content, "common/mail_template/mail_attach.ftl", srcPath);
} catch (Exception e) {
log.error("邮件服务器未配置:{}", e.getMessage());
}

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResultCodeEnum;
import cc.ryanc.halo.service.OptionsService;
import cc.ryanc.halo.utils.LocaleMessageUtil;
import freemarker.template.Configuration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,6 +32,9 @@ public class OptionController {
@Autowired
private Configuration configuration;
@Autowired
private LocaleMessageUtil localeMessageUtil;
/**
* option
*
@ -57,10 +61,10 @@ public class OptionController {
HaloConst.OPTIONS.clear();
HaloConst.OPTIONS = optionsService.findAllOptions();
log.info("所保存的设置选项列表:" + options);
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "保存成功!");
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.save-success"));
} catch (Exception e) {
log.error("保存设置选项失败:{}", e.getMessage());
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "保存失败!");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.save-failed"));
}
}
}

View File

@ -10,6 +10,7 @@ import cc.ryanc.halo.model.enums.TrueFalseEnum;
import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.OptionsService;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.utils.LocaleMessageUtil;
import cc.ryanc.halo.web.controller.core.BaseController;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
@ -53,6 +54,9 @@ public class ThemeController extends BaseController {
@Autowired
private LogsService logsService;
@Autowired
private LocaleMessageUtil localeMessageUtil;
private static final String NOT_FOUND_GIT = "-bash: git: command not found";
/**
@ -91,10 +95,10 @@ public class ThemeController extends BaseController {
logsService.saveByLogs(
new Logs(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, ServletUtil.getClientIP(request), DateUtil.date())
);
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "主题已设置为" + siteTheme);
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.theme.change-success", new Object[]{siteTheme}));
} catch (Exception e) {
log.error("主题设置失败,当前主题为:{}", siteTheme);
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "主题设置失败");
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.change-failed"));
}
}

View File

@ -123,10 +123,10 @@ admin.setting.tab.other = 其他设置
admin.pages.title = 页面管理
# 图库页面管理
admin.pages.gallery.title = 图库页面
admin.pages.galleries.title = 图库页面
# 友情链接页面管理
admin.pages.link.title = 友情链接
admin.pages.links.title = 友情链接
# 页面编辑页面
admin.pages.edit.title = 页面编辑
@ -161,6 +161,8 @@ admin.tags.title = 标签
# 主题管理页面
admin.themes.title = 主题管理
# 主题编辑页面
admin.themes.edit.title = 主题编辑
admin.themes.btn.install = 安装主题
admin.themes.btn.setting = 设置
admin.themes.btn.enable = 启用
@ -169,9 +171,6 @@ admin.themes.bread.appearance = 外观
admin.themes.js.install-theme = 安装主题
admin.themes.js.theme-setting = 主题设置
# 主题编辑页面
admin.themes.edit.title = 主题编辑
# 关于页面
admin.halo.title = 关于Halo
admin.halo.bread.active = 关于Halo
@ -201,7 +200,6 @@ common.btn.editing = 正在修改
common.btn.modify = 修改
common.btn.choose = 选择
common.radio.display = 显示
common.radio.hide = 隐藏
@ -224,7 +222,6 @@ common.th.url = 路径
common.th.desc = 描述
common.th.posts-count = 文章数
common.th.file-name = 文件名称
common.th.backup-date = 备份时间
common.th.file-size = 文件大小
common.th.file-type = 文件类型
@ -251,3 +248,27 @@ admin.pageinfo.btn.first = 首页
admin.pageinfo.btn.last = 尾页
admin.pageinfo.btn.pre = 上一页
admin.pageinfo.btn.next = 下一页
# Java代码
code.admin.login.success = 登录成功!
code.admin.login.disabled = 已禁止登录请10分钟后再试
code.admin.login.failed = 登录失败,你还有{0}次机会。
code.admin.attachment.upload-success = 上传成功!
code.admin.attachment.upload-failed = 上传失败!
code.admin.backup.backup-failed = 备份失败!
code.admin.backup.backup-success = 备份成功!
code.admin.backup.no-email = 博主邮箱没有配置!
code.admin.backup.email-success= 邮件发送成功!
code.admin.backup.have-new-backup = 有新的备份!
code.admin.theme.change-success = 主题已设置为{0}
code.admin.theme.change-failed = 主题设置失败!
code.admin.common.delete-success = 删除成功!
code.admin.common.delete-failed = 删除失败!
code.admin.common.no-post = 发信邮箱没有配置!
code.admin.common.save-success = 保存成功!
code.admin.common.save-failed = 保存失败!

View File

@ -161,7 +161,6 @@ admin.tags.title = Tags
# themes page
admin.themes.title = Themes manage
# themes edit page
admin.themes.edit.title = Theme edit
admin.themes.btn.install = Install
@ -242,10 +241,34 @@ common.text.tips.to-release-post = Are you sure you want to publish this article
common.js.all-attachment = All attachments
common.js.info-no-complate = Please enter full information!
# 分页信息
# Page info
admin.pageinfo.text.no = (
admin.pageinfo.text.page = )
admin.pageinfo.btn.first = Home
admin.pageinfo.btn.last = Last
admin.pageinfo.btn.pre = Previous
admin.pageinfo.btn.next = Next
# java code
code.admin.login.success = Login successfully!
code.admin.login.disabled = Login is forbidden, please try again in 10 minutes!
code.admin.login.failed = Login failed, you still have {0} chances.
code.admin.attachment.upload-success = Uploaded successfully!
code.admin.attachment.upload-failed = Uploaded failed!
code.admin.backup.backup-failed = Backup Failed!
code.admin.backup.backup-success = Backup successfully!
code.admin.backup.no-email = The blogger's mailbox is not configured!
code.admin.backup.email-success= Mail sent successfully!
code.admin.backup.have-new-backup = Have a new backup!
code.admin.theme.change-success = Theme has been set to {0}
code.admin.theme.change-failed = Theme settings failed!
code.admin.common.delete-success = Deleted successfully!
code.admin.common.delete-failed = Deleted Failed!
code.admin.common.no-post = The mailing mailbox is not configured!
code.admin.common.save-success = Saved successfully!
code.admin.common.save-failed = Save failed!

View File

@ -123,10 +123,10 @@ admin.setting.tab.other = 其他设置
admin.pages.title = 页面管理
# 图库页面管理
admin.pages.gallery.title = 图库页面
admin.pages.galleries.title = 图库页面
# 友情链接页面管理
admin.pages.link.title = 友情链接
admin.pages.links.title = 友情链接
# 页面编辑页面
admin.pages.edit.title = 页面编辑
@ -161,6 +161,8 @@ admin.tags.title = 标签
# 主题管理页面
admin.themes.title = 主题管理
# 主题编辑页面
admin.themes.edit.title = 主题编辑
admin.themes.btn.install = 安装主题
admin.themes.btn.setting = 设置
admin.themes.btn.enable = 启用
@ -169,9 +171,6 @@ admin.themes.bread.appearance = 外观
admin.themes.js.install-theme = 安装主题
admin.themes.js.theme-setting = 主题设置
# 主题编辑页面
admin.themes.edit.title = 主题编辑
# 关于页面
admin.halo.title = 关于Halo
admin.halo.bread.active = 关于Halo
@ -201,7 +200,6 @@ common.btn.editing = 正在修改
common.btn.modify = 修改
common.btn.choose = 选择
common.radio.display = 显示
common.radio.hide = 隐藏
@ -224,7 +222,6 @@ common.th.url = 路径
common.th.desc = 描述
common.th.posts-count = 文章数
common.th.file-name = 文件名称
common.th.backup-date = 备份时间
common.th.file-size = 文件大小
common.th.file-type = 文件类型
@ -251,3 +248,27 @@ admin.pageinfo.btn.first = 首页
admin.pageinfo.btn.last = 尾页
admin.pageinfo.btn.pre = 上一页
admin.pageinfo.btn.next = 下一页
# Java代码
code.admin.login.success = 登录成功!
code.admin.login.disabled = 已禁止登录请10分钟后再试
code.admin.login.failed = 登录失败,你还有{0}次机会。
code.admin.attachment.upload-success = 上传成功!
code.admin.attachment.upload-failed = 上传失败!
code.admin.backup.backup-failed = 备份失败!
code.admin.backup.backup-success = 备份成功!
code.admin.backup.no-email = 博主邮箱没有配置!
code.admin.backup.email-success= 邮件发送成功!
code.admin.backup.have-new-backup = 有新的备份!
code.admin.theme.change-success = 主题已设置为{0}
code.admin.theme.change-failed = 主题设置失败!
code.admin.common.delete-success = 删除成功!
code.admin.common.delete-failed = 删除失败!
code.admin.common.no-post = 发信邮箱没有配置!
code.admin.common.save-success = 保存成功!
code.admin.common.save-failed = 保存失败!

View File

@ -45,7 +45,7 @@
<div class="form-group">
<label for="cateDesc" class="control-label"><@spring.message code='admin.categories.form.cate-desc' /></label>
<textarea class="form-control" rows="3" id="cateDesc" name="cateDesc" style="resize: none">${updateCategory.cateDesc}</textarea>
<small><@spring.message code='admin.categories.form.cate-url-tips' /></small>
<small><@spring.message code='admin.categories.form.cate-desc-tips' /></small>
</div>
</div>
<div class="box-footer">
@ -72,7 +72,7 @@
<div class="form-group">
<label for="cateDesc" class="control-label"><@spring.message code='admin.categories.form.cate-desc' /></label>
<textarea class="form-control" rows="3" id="cateDesc" name="cateDesc" style="resize: none"></textarea>
<small><@spring.message code='admin.categories.form.cate-url-tips' /></small>
<small><@spring.message code='admin.categories.form.cate-desc-tips' /></small>
</div>
</div>
<div class="box-footer">