葡萄牙语-后端

This commit is contained in:
khalil
2025-07-15 11:02:50 +08:00
parent 90be8f1070
commit ecd9e446cc
7 changed files with 37 additions and 38 deletions

View File

@@ -42,4 +42,10 @@ public class I18nMessageAdminVo {
*/ */
@ApiModelProperty("土耳其语") @ApiModelProperty("土耳其语")
private String tr; private String tr;
/**
* 英语
*/
@ApiModelProperty("葡萄牙语")
private String pt;
} }

View File

@@ -1,6 +1,7 @@
package com.accompany.admin.service.system; package com.accompany.admin.service.system;
import com.accompany.admin.vo.msg.I18nMessageAdminVo; import com.accompany.admin.vo.msg.I18nMessageAdminVo;
import com.accompany.core.config.WebLocaleConfig;
import com.accompany.core.service.MessageI18nNacosService; import com.accompany.core.service.MessageI18nNacosService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -24,11 +25,11 @@ public class I18nMessageAdminService {
public List<I18nMessageAdminVo> list() { public List<I18nMessageAdminVo> list() {
List<I18nMessageAdminVo> admins = new ArrayList<>(); List<I18nMessageAdminVo> admins = new ArrayList<>();
Properties zhProperties = messageI18nNacosService.getProperties(MessageI18nNacosService.MESSAGES_ZH_CONF_DATA_ID); Properties zhProperties = messageI18nNacosService.getProperties(WebLocaleConfig.Chinese);
Properties enProperties = messageI18nNacosService.getProperties(WebLocaleConfig.English);
Properties enProperties = messageI18nNacosService.getProperties(MessageI18nNacosService.MESSAGES_EN_CONF_DATA_ID); Properties arProperties = messageI18nNacosService.getProperties(WebLocaleConfig.Arabic);
Properties arProperties = messageI18nNacosService.getProperties(MessageI18nNacosService.MESSAGES_AR_CONF_DATA_ID); Properties trProperties = messageI18nNacosService.getProperties(WebLocaleConfig.Turkey);
Properties trProperties = messageI18nNacosService.getProperties(MessageI18nNacosService.MESSAGES_TR_CONF_DATA_ID); Properties prProperties = messageI18nNacosService.getProperties(WebLocaleConfig.Portuguese);
for (Object obj : zhProperties.keySet()) { for (Object obj : zhProperties.keySet()) {
String key = obj.toString(); String key = obj.toString();
I18nMessageAdminVo admin = new I18nMessageAdminVo(); I18nMessageAdminVo admin = new I18nMessageAdminVo();
@@ -37,15 +38,17 @@ public class I18nMessageAdminService {
admin.setEn(enProperties.getProperty(key)); admin.setEn(enProperties.getProperty(key));
admin.setAr(arProperties.getProperty(key)); admin.setAr(arProperties.getProperty(key));
admin.setTr(trProperties.getProperty(key)); admin.setTr(trProperties.getProperty(key));
admin.setPt(prProperties.getProperty(key));
admins.add(admin); admins.add(admin);
} }
return admins; return admins;
} }
public void save(String key, String zh, String en, String ar, String tr) { public void save(String key, String zh, String en, String ar, String tr, String pt) {
messageI18nNacosService.saveOrUpdateProperties(key, zh, MessageI18nNacosService.MESSAGES_ZH_CONF_DATA_ID); messageI18nNacosService.saveOrUpdateProperties(WebLocaleConfig.Chinese, key, zh);
messageI18nNacosService.saveOrUpdateProperties(key, en, MessageI18nNacosService.MESSAGES_EN_CONF_DATA_ID); messageI18nNacosService.saveOrUpdateProperties(WebLocaleConfig.English, key, en);
messageI18nNacosService.saveOrUpdateProperties(key, ar, MessageI18nNacosService.MESSAGES_AR_CONF_DATA_ID); messageI18nNacosService.saveOrUpdateProperties(WebLocaleConfig.Arabic, key, ar);
messageI18nNacosService.saveOrUpdateProperties(key, tr, MessageI18nNacosService.MESSAGES_TR_CONF_DATA_ID); messageI18nNacosService.saveOrUpdateProperties(WebLocaleConfig.Turkey, key, tr);
messageI18nNacosService.saveOrUpdateProperties(WebLocaleConfig.Portuguese, key, pt);
} }
} }

View File

@@ -46,7 +46,7 @@ public class I18nMessageAdminController {
@ApiOperation("保存") @ApiOperation("保存")
@PostMapping("save") @PostMapping("save")
public BusiResult<Void> save(I18nMessageAdminVo param) { public BusiResult<Void> save(I18nMessageAdminVo param) {
i18nMessageAdminService.save(param.getKey(), param.getZh(), param.getEn(), param.getAr(), param.getTr()); i18nMessageAdminService.save(param.getKey(), param.getZh(), param.getEn(), param.getAr(), param.getTr(), param.getPt());
return BusiResult.success(); return BusiResult.success();
} }
} }

View File

@@ -180,7 +180,7 @@ public class I18NMessageSourceUtil {
field.set(obj, zhValue); field.set(obj, zhValue);
} }
} }
if (refreshLocalSet.size() > 0) { if (!refreshLocalSet.isEmpty()) {
messageI18nNacosService.refreshForce(refreshLocalSet); messageI18nNacosService.refreshForce(refreshLocalSet);
} }
//SpringContextHolder.getBean(I18nMessageNacosAutoConfig.class).initTip(); //SpringContextHolder.getBean(I18nMessageNacosAutoConfig.class).initTip();

View File

@@ -16,16 +16,9 @@ public class WebLocaleConfig implements WebMvcConfigurer {
// 阿拉伯语 // 阿拉伯语
public static Locale Arabic = new Locale("ar"); public static Locale Arabic = new Locale("ar");
public static Locale Turkey = new Locale("tr"); public static Locale Turkey = new Locale("tr");
public static Locale Portuguese = new Locale("pt");
public static List<Locale> locales = Arrays.asList(Chinese, English, Arabic, Turkey); public static List<Locale> locales = Arrays.asList(Chinese, English, Arabic, Turkey, Portuguese);
public static Map<String, Locale> localeMap = new HashMap<>();
static {
localeMap.put(Chinese.getLanguage(), Chinese);
localeMap.put(English.getLanguage(), English);
localeMap.put(Arabic.getLanguage(), Arabic);
localeMap.put(Turkey.getLanguage(), Turkey);
}
/** /**
* 国际化默认解析器,默认设置为汉语 * 国际化默认解析器,默认设置为汉语

View File

@@ -13,6 +13,7 @@ public enum PartitionEnum {
CHINESE(4, "Asia/Hong_Kong", "中文区", "zh", Constant.ClanMode.CLAN_HALL), CHINESE(4, "Asia/Hong_Kong", "中文区", "zh", Constant.ClanMode.CLAN_HALL),
TURKEY(8, "Europe/Istanbul", "土耳其区", "tr", Constant.ClanMode.GUILD), TURKEY(8, "Europe/Istanbul", "土耳其区", "tr", Constant.ClanMode.GUILD),
ENGLISH2(16, "Asia/Manila", "英语2区", "en", Constant.ClanMode.GUILD), ENGLISH2(16, "Asia/Manila", "英语2区", "en", Constant.ClanMode.GUILD),
PORTUGUESE(32, "America/Sao_Paulo", "葡萄牙语区", "pr", Constant.ClanMode.GUILD),
; ;
private final int id; private final int id;

View File

@@ -41,26 +41,16 @@ public class MessageI18nNacosService implements InitializingBean {
@Getter @Getter
private ConfigService i18nNacosConfigService; private ConfigService i18nNacosConfigService;
/**
* 国际化英文配置属性文件
*/
public static final String MESSAGES_EN_CONF_DATA_ID = "messages_en.properties";
/**
* 国际化阿拉伯语语配置属性文件
*/
public static final String MESSAGES_AR_CONF_DATA_ID = "messages_ar.properties";
/**
* 国际化中文配置属性文件
*/
public static final String MESSAGES_ZH_CONF_DATA_ID = "messages_zh.properties";
/**
* 国际化中文配置属性文件
*/
public static final String MESSAGES_TR_CONF_DATA_ID = "messages_tr.properties";
private static final String GROUP = "DEFAULT_GROUP"; private static final String GROUP = "DEFAULT_GROUP";
@SneakyThrows
public boolean saveOrUpdateProperties(Locale locale, String key, String value) {
// 创建Nacos配置服务实例
String messageId = getMessageFileName(locale.getLanguage());
return saveOrUpdateProperties(key, value, messageId);
}
/** /**
* 修改或者更新国际化数据 * 修改或者更新国际化数据
* *
@@ -85,6 +75,12 @@ public class MessageI18nNacosService implements InitializingBean {
newContent); newContent);
} }
@SneakyThrows
public Properties getProperties(Locale locale) {
String messageId = getMessageFileName(locale.getLanguage());
return getProperties(messageId);
}
@SneakyThrows @SneakyThrows
public Properties getProperties(String messageId) { public Properties getProperties(String messageId) {
// 创建Nacos配置服务实例 // 创建Nacos配置服务实例