mirror of https://gitee.com/stylefeng/roses
【i18n】初始化多语言模块
parent
cd33e36957
commit
291607886b
|
@ -0,0 +1 @@
|
|||
# 多语言模块
|
|
@ -0,0 +1 @@
|
|||
多语言模块的api
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-i18n</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>i18n-api</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--校验模块的api-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>validator-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,36 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.i18n.api.enums.TranslationEnum;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.TranslationDict;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 多语言翻译服务api
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 18:50
|
||||
*/
|
||||
public interface TranslationApi {
|
||||
|
||||
/**
|
||||
* 初始化多语言翻译字典
|
||||
*
|
||||
* @param translationDict 所有翻译的值
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:00
|
||||
*/
|
||||
void init(List<TranslationDict> translationDict);
|
||||
|
||||
/**
|
||||
* 获取某个语种下的所有多语言字典
|
||||
*
|
||||
* @param translationLanguages 语种枚举
|
||||
* @return key-翻译项标识,value-翻译的值TranslationApi
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:01
|
||||
*/
|
||||
Map<String, String> getTranslationDictByLanguage(TranslationEnum translationLanguages);
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.TranslationDict;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 多语言字典持久化api
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:32
|
||||
*/
|
||||
public interface TranslationPersistenceApi {
|
||||
|
||||
/**
|
||||
* 获取所有的翻译项
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:33
|
||||
*/
|
||||
List<TranslationDict> getAllTranslationDict();
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api.constants;
|
||||
|
||||
/**
|
||||
* 多语言模块的常量
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 16:36
|
||||
*/
|
||||
public interface TranslationConstants {
|
||||
|
||||
/**
|
||||
* 多语言模块的名称
|
||||
*/
|
||||
String I18N_MODULE_NAME = "kernel-d-i18n";
|
||||
|
||||
/**
|
||||
* 异常枚举的步进值
|
||||
*/
|
||||
String I18N_EXCEPTION_STEP_CODE = "25";
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api.context;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.TranslationApi;
|
||||
|
||||
/**
|
||||
* 翻译上下文获取
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:06
|
||||
*/
|
||||
public class TranslationContext {
|
||||
|
||||
/**
|
||||
* 获取翻译接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:06
|
||||
*/
|
||||
public TranslationApi me() {
|
||||
return SpringUtil.getBean(TranslationApi.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 翻译的语种
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 18:57
|
||||
*/
|
||||
@Getter
|
||||
public enum TranslationEnum {
|
||||
|
||||
/**
|
||||
* 中文
|
||||
*/
|
||||
CHINESE(1, "中文"),
|
||||
|
||||
/**
|
||||
* 英文
|
||||
*/
|
||||
ENGLISH(2, "English");
|
||||
|
||||
/**
|
||||
* 语种编码
|
||||
*/
|
||||
private final Integer code;
|
||||
|
||||
/**
|
||||
* 语种的中文描述
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
TranslationEnum(Integer code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的type(返回code编码集合)
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2019/10/18 10:13
|
||||
*/
|
||||
public static List<String> types() {
|
||||
ArrayList<String> integers = new ArrayList<>();
|
||||
for (TranslationEnum value : TranslationEnum.values()) {
|
||||
integers.add(value.name());
|
||||
}
|
||||
return integers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过code值获取枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2019/10/18 10:33
|
||||
*/
|
||||
public static TranslationEnum valueOf(Integer value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
} else {
|
||||
for (TranslationEnum translationLanguages : TranslationEnum.values()) {
|
||||
if (translationLanguages.getCode().equals(value)) {
|
||||
return translationLanguages;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api.exception;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.constants.TranslationConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
|
||||
/**
|
||||
* 多语言翻译的异常
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/10/15 15:59
|
||||
*/
|
||||
public class TranslationException extends ServiceException {
|
||||
|
||||
public TranslationException(AbstractExceptionEnum exception, Object... params) {
|
||||
super(TranslationConstants.I18N_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
|
||||
}
|
||||
|
||||
public TranslationException(AbstractExceptionEnum exception) {
|
||||
super(TranslationConstants.I18N_MODULE_NAME, exception);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api.exception.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.i18n.api.constants.TranslationConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 多语言翻译的异常枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 16:40
|
||||
*/
|
||||
@Getter
|
||||
public enum TranslationExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 多语言xx
|
||||
*/
|
||||
JWT_PARSE_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + TranslationConstants.I18N_EXCEPTION_STEP_CODE + "01", "jwt解析错误!jwt为:{}");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
TranslationExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.i18n.api.enums.TranslationEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 多语言翻译信息
|
||||
*
|
||||
* @author stylefeng
|
||||
* @since 2019-10-17
|
||||
*/
|
||||
@Data
|
||||
public class TranslationDict implements Serializable {
|
||||
|
||||
/**
|
||||
* 翻译项的编码,例如:FIELD_ACCOUNT
|
||||
*/
|
||||
private String tranCode;
|
||||
|
||||
/**
|
||||
* 多语言翻译项的说明,例如:针对账号输入框的
|
||||
*/
|
||||
private String tranName;
|
||||
|
||||
/**
|
||||
* 1:中文 2:英语
|
||||
*/
|
||||
private TranslationEnum translationLanguages;
|
||||
|
||||
/**
|
||||
* 翻译的值,例如:账号
|
||||
*/
|
||||
private String tranValue;
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.api.pojo.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 多语言请求信息
|
||||
*
|
||||
* @author stylefeng
|
||||
* @since 2019-10-17
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class TranslationRequest extends BaseRequest {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
private Long tranId;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String tranCode;
|
||||
|
||||
/**
|
||||
* 多语言条例名称
|
||||
*/
|
||||
private String tranName;
|
||||
|
||||
/**
|
||||
* 1:中文 2:英语
|
||||
*/
|
||||
private Integer languages;
|
||||
|
||||
/**
|
||||
* 翻译的值
|
||||
*/
|
||||
private String tranValue;
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
多语言模块的数据管理业务
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-i18n</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>i18n-business</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--多语言翻译的sdk-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>i18n-sdk</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--资源api模块-->
|
||||
<!--用在资源控制器,资源扫描上-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>scanner-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--参数校验模块-->
|
||||
<!--用在控制器,参数校验-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>validator-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--数据库sdk-->
|
||||
<!--数据库dao框架-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>db-sdk-mp</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--web模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,90 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.request.TranslationRequest;
|
||||
import cn.stylefeng.roses.kernel.i18n.modular.entity.Translation;
|
||||
import cn.stylefeng.roses.kernel.i18n.modular.service.TranslationService;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 多语言接口控制器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:18
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "多语言接口控制器")
|
||||
public class TranslationController {
|
||||
|
||||
@Resource
|
||||
private TranslationService translationService;
|
||||
|
||||
/**
|
||||
* 新增多语言翻译记录
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:17
|
||||
*/
|
||||
@PostResource(name = "新增多语言配置", path = "/i18n/add")
|
||||
public ResponseData addItem(TranslationRequest translationRequest) {
|
||||
this.translationService.add(translationRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑多语言翻译记录
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:17
|
||||
*/
|
||||
@PostResource(name = "新增多语言配置", path = "/i18n/edit")
|
||||
public ResponseData editItem(TranslationRequest translationRequest) {
|
||||
this.translationService.update(translationRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除多语言配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:20
|
||||
*/
|
||||
@PostResource(name = "新增多语言配置", path = "/i18n/delete")
|
||||
public ResponseData delete(TranslationRequest translationRequest) {
|
||||
this.translationService.delete(translationRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看多语言详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:20
|
||||
*/
|
||||
@PostResource(name = "新增多语言配置", path = "/i18n/detail")
|
||||
public ResponseData detail(TranslationRequest translationRequest) {
|
||||
Translation detail = this.translationService.findDetail(translationRequest);
|
||||
return new SuccessResponseData(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看多语言配置列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:20
|
||||
*/
|
||||
@PostResource(name = "新增多语言配置", path = "/i18n/page")
|
||||
public ResponseData list(TranslationRequest translationRequest) {
|
||||
PageResult<Translation> page = this.translationService.findPage(translationRequest);
|
||||
return new SuccessResponseData(page);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.modular.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 多语言表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:12
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_translation")
|
||||
@Data
|
||||
public class Translation extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value = "tran_id", type = IdType.ASSIGN_ID)
|
||||
private Long tranId;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@TableField("tran_code")
|
||||
private String tranCode;
|
||||
|
||||
/**
|
||||
* 多语言条例名称
|
||||
*/
|
||||
@TableField("tran_name")
|
||||
private String tranName;
|
||||
|
||||
/**
|
||||
* 1:中文 2:英语
|
||||
*/
|
||||
@TableField("languages")
|
||||
private Integer languages;
|
||||
|
||||
/**
|
||||
* 翻译的值
|
||||
*/
|
||||
@TableField("tran_value")
|
||||
private String tranValue;
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.modular.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.i18n.modular.entity.Translation;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 多语言表 Mapper 接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:22
|
||||
*/
|
||||
public interface TranslationMapper extends BaseMapper<Translation> {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.guns.i18n.mapper.TranslationMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,57 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.modular.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.TranslationPersistenceApi;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.request.TranslationRequest;
|
||||
import cn.stylefeng.roses.kernel.i18n.modular.entity.Translation;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 多语言表 服务类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:21
|
||||
*/
|
||||
public interface TranslationService extends IService<Translation>, TranslationPersistenceApi {
|
||||
|
||||
/**
|
||||
* 新增翻译项
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:27
|
||||
*/
|
||||
void add(TranslationRequest param);
|
||||
|
||||
/**
|
||||
* 更新翻译项
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:27
|
||||
*/
|
||||
void update(TranslationRequest param);
|
||||
|
||||
/**
|
||||
* 删除翻译项
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:27
|
||||
*/
|
||||
void delete(TranslationRequest param);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:28
|
||||
*/
|
||||
Translation findDetail(TranslationRequest param);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:28
|
||||
*/
|
||||
PageResult<Translation> findPage(TranslationRequest param);
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.modular.service.impl;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.TranslationDict;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.request.TranslationRequest;
|
||||
import cn.stylefeng.roses.kernel.i18n.modular.entity.Translation;
|
||||
import cn.stylefeng.roses.kernel.i18n.modular.mapper.TranslationMapper;
|
||||
import cn.stylefeng.roses.kernel.i18n.modular.service.TranslationService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 多语言管理业务
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:38
|
||||
*/
|
||||
@Service
|
||||
public class TranslationServiceImpl extends ServiceImpl<TranslationMapper, Translation> implements TranslationService {
|
||||
|
||||
@Override
|
||||
public void add(TranslationRequest param) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TranslationRequest param) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(TranslationRequest param) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Translation findDetail(TranslationRequest param) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Translation> findPage(TranslationRequest param) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TranslationDict> getAllTranslationDict() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
多语言模块的sdk
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-i18n</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>i18n-sdk</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--多语言的api-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>i18n-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,49 @@
|
|||
package cn.stylefeng.roses.kernel.i18n;
|
||||
|
||||
import cn.stylefeng.roses.kernel.i18n.api.TranslationApi;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.enums.TranslationEnum;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.TranslationDict;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 翻译字典的容器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:08
|
||||
*/
|
||||
public class TranslationContainer implements TranslationApi {
|
||||
|
||||
/**
|
||||
* 所有翻译的条目的字典项
|
||||
* <p>
|
||||
* key是语种,value是对应语种下的所有key value翻译值(第二个key是具体翻译项的编码)
|
||||
*/
|
||||
private static final Map<TranslationEnum, Map<String, String>> TRAN_DICT_CONTAINER = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void init(List<TranslationDict> translationDict) {
|
||||
|
||||
// 根据语种数量,创建多个语种的翻译Map
|
||||
for (TranslationEnum type : TranslationEnum.values()) {
|
||||
HashMap<String, String> typeMap = new HashMap<>();
|
||||
TRAN_DICT_CONTAINER.put(type, typeMap);
|
||||
}
|
||||
|
||||
// 整理数据库中的字典
|
||||
for (TranslationDict translationItem : translationDict) {
|
||||
TranslationEnum translationLanguages = translationItem.getTranslationLanguages();
|
||||
TRAN_DICT_CONTAINER.get(translationLanguages).put(translationItem.getTranCode(), translationItem.getTranValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getTranslationDictByLanguage(TranslationEnum translationLanguages) {
|
||||
return TRAN_DICT_CONTAINER.get(translationLanguages);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.listener;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.TranslationApi;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.TranslationPersistenceApi;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.pojo.TranslationDict;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.event.ApplicationContextInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 初始化系统配置表
|
||||
* <p>
|
||||
* 当spring装配好配置后,就去数据库读constants
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 19:36
|
||||
*/
|
||||
@Slf4j
|
||||
public class TranslationDictInitListener implements ApplicationListener<ApplicationContextInitializedEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationContextInitializedEvent applicationContextInitializedEvent) {
|
||||
|
||||
TranslationPersistenceApi tanTranslationPersistenceApi = SpringUtil.getBean(TranslationPersistenceApi.class);
|
||||
TranslationApi translationApi = SpringUtil.getBean(TranslationApi.class);
|
||||
|
||||
// 从数据库读取字典
|
||||
List<TranslationDict> allTranslationDict = tanTranslationPersistenceApi.getAllTranslationDict();
|
||||
if (allTranslationDict != null) {
|
||||
translationApi.init(allTranslationDict);
|
||||
log.info("初始化所有的翻译字典" + allTranslationDict.size() + "条!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
多语言模块的spring boot自动配置
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-i18n</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>i18n-spring-boot-starter</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--多语言的sdk-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>i18n-sdk</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.i18n.starter;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 多语言翻译的自动配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/24 16:42
|
||||
*/
|
||||
@Configuration
|
||||
public class GunsTranslationAutoConfiguration {
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.stylefeng.roses.kernel.i18n.starter.GunsTranslationAutoConfiguration
|
||||
org.springframework.context.ApplicationListener=\
|
||||
cn.stylefeng.roses.kernel.i18n.listener.TranslationDictInitListener
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>kernel-d-i18n</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>i18n-api</module>
|
||||
<module>i18n-business</module>
|
||||
<module>i18n-sdk</module>
|
||||
<module>i18n-spring-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 开发规则 -->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-a-rule</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue