TASK: 枚举类多语言;

This commit is contained in:
shahaibo
2023-11-23 10:32:33 +08:00
parent 5213b03598
commit ecec69a45e
3 changed files with 23 additions and 7 deletions

View File

@@ -53,7 +53,11 @@ public class BusinessException extends RuntimeException {
return new Locale(Language.valueOf(userInfo.getLanguage()).getValue());
}
private static String getMessageFromResource(String msg, Locale userLocale) {
public static String getMessageFromResource(String msg) {
return getMessageFromResource(msg, getUserLocale());
}
public static String getMessageFromResource(String msg, Locale userLocale) {
try (InputStream inputStream = BusinessException.class.getClassLoader().getResourceAsStream("messages_" + userLocale.getLanguage() + ".properties")) {
if (inputStream != null) {
ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(inputStream, StandardCharsets.UTF_8));

View File

@@ -196,8 +196,8 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
}
Sex sex = Sex.getSex(workspaceVO.getSex());
Position position = Position.getPosition(workspaceVO.getPosition());
workspaceVO.setSexEnum(new BizJson(sex.getValue(), sex.name(), null));
workspaceVO.setPositionEnum(new BizJson(position.getValue(), position.name(), null));
workspaceVO.setSexEnum(new BizJson(sex.getValue(), sex.name(), BusinessException.getMessageFromResource(sex.name())));
workspaceVO.setPositionEnum(new BizJson(position.getValue(), position.name(), BusinessException.getMessageFromResource(position.name())));
return workspaceVO;
}
);
@@ -224,8 +224,8 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
}
Sex sex = Sex.getSex(workspaceVO.getSex());
Position position = Position.getPosition(workspaceVO.getPosition());
workspaceVO.setSexEnum(new BizJson(sex.getValue(), sex.name(), null));
workspaceVO.setPositionEnum(new BizJson(position.getValue(), position.name(), null));
workspaceVO.setSexEnum(new BizJson(sex.getValue(), sex.name(), BusinessException.getMessageFromResource(sex.name())));
workspaceVO.setPositionEnum(new BizJson(position.getValue(), position.name(), BusinessException.getMessageFromResource(position.name())));
return workspaceVO;
}
);
@@ -588,7 +588,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
List<BizJson> kvs = new ArrayList<BizJson>();
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();
for (IEnumDisplay item : items) {
kvs.add(new BizJson(item.getValue(), item.name(), null));
kvs.add(new BizJson(item.getValue(), item.name(), BusinessException.getMessageFromResource(item.name())));
}
return kvs;
}

View File

@@ -161,4 +161,16 @@ processSketchBoards.interface.exception=We encountered an error uploading sketch
designProcess.interface.exception=There's been an issue loading the progress bar. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
generate.interface.exception=We are currently experiencing a high volume of generating requests. (Please try again later. If the problem continues, reach out to us at help@aida.com.hk for support.)
generate.interface.error=We encountered an error with the generate interface. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
chat-bot.interface.exception=We encountered an error with the chat robot interface.(Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
chat-bot.interface.exception=We encountered an error with the chat robot interface.(Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
# 多语言返回
OVERALL=Overall
TOPS=Tops
BOTTOMS=Bottoms
OUTWEAR=Outwear
BLOUSE=Blouse
DRESS=Dress
TROUSERS=Trousers
SKIRT=Skirt
FEMALE=Female
MALE=Male