diff --git a/kernel-d-i18n/README.md b/kernel-d-i18n/README.md new file mode 100644 index 000000000..731dd1f5a --- /dev/null +++ b/kernel-d-i18n/README.md @@ -0,0 +1 @@ +# 多语言模块 diff --git a/kernel-d-i18n/i18n-api/README.md b/kernel-d-i18n/i18n-api/README.md new file mode 100644 index 000000000..f7ae97849 --- /dev/null +++ b/kernel-d-i18n/i18n-api/README.md @@ -0,0 +1 @@ +多语言模块的api diff --git a/kernel-d-i18n/i18n-api/pom.xml b/kernel-d-i18n/i18n-api/pom.xml new file mode 100644 index 000000000..c071e8db8 --- /dev/null +++ b/kernel-d-i18n/i18n-api/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + cn.stylefeng.roses + kernel-d-i18n + 1.0.0 + ../pom.xml + + + i18n-api + + jar + + + + + + cn.stylefeng.roses + validator-api + 1.0.0 + + + + + diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/TranslationApi.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/TranslationApi.java new file mode 100644 index 000000000..344f635ee --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/TranslationApi.java @@ -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); + + /** + * 获取某个语种下的所有多语言字典 + * + * @param translationLanguages 语种枚举 + * @return key-翻译项标识,value-翻译的值TranslationApi + * @author fengshuonan + * @date 2021/1/24 19:01 + */ + Map getTranslationDictByLanguage(TranslationEnum translationLanguages); + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/TranslationPersistenceApi.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/TranslationPersistenceApi.java new file mode 100644 index 000000000..33e6aa00c --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/TranslationPersistenceApi.java @@ -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 getAllTranslationDict(); + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/constants/TranslationConstants.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/constants/TranslationConstants.java new file mode 100644 index 000000000..f551789e6 --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/constants/TranslationConstants.java @@ -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"; + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/context/TranslationContext.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/context/TranslationContext.java new file mode 100644 index 000000000..b7dc51369 --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/context/TranslationContext.java @@ -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); + } + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/enums/TranslationEnum.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/enums/TranslationEnum.java new file mode 100644 index 000000000..dba67f2cf --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/enums/TranslationEnum.java @@ -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 types() { + ArrayList 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; + } + } + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/exception/TranslationException.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/exception/TranslationException.java new file mode 100644 index 000000000..d1204fc7d --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/exception/TranslationException.java @@ -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); + } + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/exception/enums/TranslationExceptionEnum.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/exception/enums/TranslationExceptionEnum.java new file mode 100644 index 000000000..fda71f1e6 --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/exception/enums/TranslationExceptionEnum.java @@ -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; + } + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/pojo/TranslationDict.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/pojo/TranslationDict.java new file mode 100644 index 000000000..c484c025e --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/pojo/TranslationDict.java @@ -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; + +} diff --git a/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/pojo/request/TranslationRequest.java b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/pojo/request/TranslationRequest.java new file mode 100644 index 000000000..a367bc84b --- /dev/null +++ b/kernel-d-i18n/i18n-api/src/main/java/cn/stylefeng/roses/kernel/i18n/api/pojo/request/TranslationRequest.java @@ -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; + +} diff --git a/kernel-d-i18n/i18n-business/README.md b/kernel-d-i18n/i18n-business/README.md new file mode 100644 index 000000000..e433aa788 --- /dev/null +++ b/kernel-d-i18n/i18n-business/README.md @@ -0,0 +1 @@ +多语言模块的数据管理业务 diff --git a/kernel-d-i18n/i18n-business/pom.xml b/kernel-d-i18n/i18n-business/pom.xml new file mode 100644 index 000000000..657c07772 --- /dev/null +++ b/kernel-d-i18n/i18n-business/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + + cn.stylefeng.roses + kernel-d-i18n + 1.0.0 + ../pom.xml + + + i18n-business + + jar + + + + + + cn.stylefeng.roses + i18n-sdk + 1.0.0 + + + + + + cn.stylefeng.roses + scanner-api + 1.0.0 + + + + + + cn.stylefeng.roses + validator-api + 1.0.0 + + + + + + cn.stylefeng.roses + db-sdk-mp + 1.0.0 + + + + + org.springframework.boot + spring-boot-starter-web + + + + + diff --git a/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/controller/TranslationController.java b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/controller/TranslationController.java new file mode 100644 index 000000000..3dedd1332 --- /dev/null +++ b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/controller/TranslationController.java @@ -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 page = this.translationService.findPage(translationRequest); + return new SuccessResponseData(page); + } + +} + + diff --git a/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/entity/Translation.java b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/entity/Translation.java new file mode 100644 index 000000000..b2dacec12 --- /dev/null +++ b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/entity/Translation.java @@ -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; + +} diff --git a/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/mapper/TranslationMapper.java b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/mapper/TranslationMapper.java new file mode 100644 index 000000000..abc00b1bf --- /dev/null +++ b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/mapper/TranslationMapper.java @@ -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 { + + +} diff --git a/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/mapper/mapping/TranslationMapper.xml b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/mapper/mapping/TranslationMapper.xml new file mode 100644 index 000000000..c0d48f078 --- /dev/null +++ b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/mapper/mapping/TranslationMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/service/TranslationService.java b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/service/TranslationService.java new file mode 100644 index 000000000..f8be87c29 --- /dev/null +++ b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/service/TranslationService.java @@ -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, 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 findPage(TranslationRequest param); + +} diff --git a/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/service/impl/TranslationServiceImpl.java b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/service/impl/TranslationServiceImpl.java new file mode 100644 index 000000000..d9696dbba --- /dev/null +++ b/kernel-d-i18n/i18n-business/src/main/java/cn/stylefeng/roses/kernel/i18n/modular/service/impl/TranslationServiceImpl.java @@ -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 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 findPage(TranslationRequest param) { + return null; + } + + @Override + public List getAllTranslationDict() { + return null; + } + +} diff --git a/kernel-d-i18n/i18n-sdk/README.md b/kernel-d-i18n/i18n-sdk/README.md new file mode 100644 index 000000000..2deb2ce3d --- /dev/null +++ b/kernel-d-i18n/i18n-sdk/README.md @@ -0,0 +1 @@ +多语言模块的sdk diff --git a/kernel-d-i18n/i18n-sdk/pom.xml b/kernel-d-i18n/i18n-sdk/pom.xml new file mode 100644 index 000000000..907e6256b --- /dev/null +++ b/kernel-d-i18n/i18n-sdk/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + cn.stylefeng.roses + kernel-d-i18n + 1.0.0 + ../pom.xml + + + i18n-sdk + + jar + + + + + + cn.stylefeng.roses + i18n-api + 1.0.0 + + + + + diff --git a/kernel-d-i18n/i18n-sdk/src/main/java/cn/stylefeng/roses/kernel/i18n/TranslationContainer.java b/kernel-d-i18n/i18n-sdk/src/main/java/cn/stylefeng/roses/kernel/i18n/TranslationContainer.java new file mode 100644 index 000000000..45355e2bd --- /dev/null +++ b/kernel-d-i18n/i18n-sdk/src/main/java/cn/stylefeng/roses/kernel/i18n/TranslationContainer.java @@ -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 { + + /** + * 所有翻译的条目的字典项 + *

+ * key是语种,value是对应语种下的所有key value翻译值(第二个key是具体翻译项的编码) + */ + private static final Map> TRAN_DICT_CONTAINER = new ConcurrentHashMap<>(); + + @Override + public void init(List translationDict) { + + // 根据语种数量,创建多个语种的翻译Map + for (TranslationEnum type : TranslationEnum.values()) { + HashMap 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 getTranslationDictByLanguage(TranslationEnum translationLanguages) { + return TRAN_DICT_CONTAINER.get(translationLanguages); + } + +} diff --git a/kernel-d-i18n/i18n-sdk/src/main/java/cn/stylefeng/roses/kernel/i18n/listener/TranslationDictInitListener.java b/kernel-d-i18n/i18n-sdk/src/main/java/cn/stylefeng/roses/kernel/i18n/listener/TranslationDictInitListener.java new file mode 100644 index 000000000..b7d3141c0 --- /dev/null +++ b/kernel-d-i18n/i18n-sdk/src/main/java/cn/stylefeng/roses/kernel/i18n/listener/TranslationDictInitListener.java @@ -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; + +/** + * 初始化系统配置表 + *

+ * 当spring装配好配置后,就去数据库读constants + * + * @author fengshuonan + * @date 2021/1/24 19:36 + */ +@Slf4j +public class TranslationDictInitListener implements ApplicationListener { + + @Override + public void onApplicationEvent(ApplicationContextInitializedEvent applicationContextInitializedEvent) { + + TranslationPersistenceApi tanTranslationPersistenceApi = SpringUtil.getBean(TranslationPersistenceApi.class); + TranslationApi translationApi = SpringUtil.getBean(TranslationApi.class); + + // 从数据库读取字典 + List allTranslationDict = tanTranslationPersistenceApi.getAllTranslationDict(); + if (allTranslationDict != null) { + translationApi.init(allTranslationDict); + log.info("初始化所有的翻译字典" + allTranslationDict.size() + "条!"); + } + } + +} diff --git a/kernel-d-i18n/i18n-spring-boot-starter/README.md b/kernel-d-i18n/i18n-spring-boot-starter/README.md new file mode 100644 index 000000000..60643e8bc --- /dev/null +++ b/kernel-d-i18n/i18n-spring-boot-starter/README.md @@ -0,0 +1 @@ +多语言模块的spring boot自动配置 diff --git a/kernel-d-i18n/i18n-spring-boot-starter/pom.xml b/kernel-d-i18n/i18n-spring-boot-starter/pom.xml new file mode 100644 index 000000000..cab3005fa --- /dev/null +++ b/kernel-d-i18n/i18n-spring-boot-starter/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + cn.stylefeng.roses + kernel-d-i18n + 1.0.0 + ../pom.xml + + + i18n-spring-boot-starter + + jar + + + + + + cn.stylefeng.roses + i18n-sdk + 1.0.0 + + + + + diff --git a/kernel-d-i18n/i18n-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/i18n/starter/GunsTranslationAutoConfiguration.java b/kernel-d-i18n/i18n-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/i18n/starter/GunsTranslationAutoConfiguration.java new file mode 100644 index 000000000..c76f913e8 --- /dev/null +++ b/kernel-d-i18n/i18n-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/i18n/starter/GunsTranslationAutoConfiguration.java @@ -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 { + +} diff --git a/kernel-d-i18n/i18n-spring-boot-starter/src/main/resources/META-INF/spring.factories b/kernel-d-i18n/i18n-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..e82e4b724 --- /dev/null +++ b/kernel-d-i18n/i18n-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -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 diff --git a/kernel-d-i18n/pom.xml b/kernel-d-i18n/pom.xml new file mode 100644 index 000000000..9e874e60a --- /dev/null +++ b/kernel-d-i18n/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + + cn.stylefeng.roses + roses-kernel + 1.0.0 + ../pom.xml + + + kernel-d-i18n + + pom + + + i18n-api + i18n-business + i18n-sdk + i18n-spring-boot-starter + + + + + + + cn.stylefeng.roses + kernel-a-rule + 1.0.0 + + + + + diff --git a/pom.xml b/pom.xml index de68c8474..db4791b8f 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,9 @@ kernel-d-file + + kernel-d-i18n + kernel-d-sms