영어버전도 나오게 추가
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.kamco.cd.training.common.utils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
public final class HeaderUtil {
|
||||
|
||||
@@ -20,4 +23,20 @@ public final class HeaderUtil {
|
||||
public static String getRequired(HttpServletRequest request, String headerName) {
|
||||
return get(request, headerName);
|
||||
}
|
||||
|
||||
public static boolean isEnglishRequest() {
|
||||
RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
|
||||
|
||||
if (!(attrs instanceof ServletRequestAttributes servletAttrs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String acceptLanguage = servletAttrs.getRequest().getHeader("Accept-Language");
|
||||
|
||||
if (acceptLanguage == null || acceptLanguage.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return acceptLanguage.toLowerCase().startsWith("en");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kamco.cd.training.common.utils.enums;
|
||||
|
||||
import com.kamco.cd.training.common.utils.HeaderUtil;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -31,10 +32,11 @@ public class Enums {
|
||||
// enum -> CodeDto list
|
||||
public static List<CodeDto> toList(Class<? extends Enum<?>> enumClass) {
|
||||
Object[] enums = enumClass.getEnumConstants();
|
||||
boolean english = HeaderUtil.isEnglishRequest();
|
||||
|
||||
return Arrays.stream(enums)
|
||||
.map(e -> (EnumType) e)
|
||||
.map(e -> new CodeDto(e.getId(), e.getText()))
|
||||
.map(e -> new CodeDto(e.getId(), english ? e.getId() : e.getText()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.kamco.cd.training.common.enums.LearnDataRegister;
|
||||
import com.kamco.cd.training.common.enums.LearnDataType;
|
||||
import com.kamco.cd.training.common.enums.ModelType;
|
||||
import com.kamco.cd.training.common.utils.HeaderUtil;
|
||||
import com.kamco.cd.training.common.utils.enums.Enums;
|
||||
import com.kamco.cd.training.common.utils.interfaces.JsonFormatDttm;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -90,7 +91,8 @@ public class DatasetDto {
|
||||
|
||||
public String getStatus(String status) {
|
||||
LearnDataRegister type = Enums.fromId(LearnDataRegister.class, status);
|
||||
return type == null ? null : type.getText();
|
||||
boolean english = HeaderUtil.isEnglishRequest();
|
||||
return type == null ? null : (english ? type.getId() : type.getText());
|
||||
}
|
||||
|
||||
public String getYear() {
|
||||
@@ -99,7 +101,8 @@ public class DatasetDto {
|
||||
|
||||
public String getDataTypeName() {
|
||||
LearnDataType type = Enums.fromId(LearnDataType.class, this.dataType);
|
||||
return type == null ? null : type.getText();
|
||||
boolean english = HeaderUtil.isEnglishRequest();
|
||||
return type == null ? null : (english ? type.getId() : type.getText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kamco.cd.training.model.dto;
|
||||
import com.kamco.cd.training.common.dto.HyperParam;
|
||||
import com.kamco.cd.training.common.enums.TrainStatusType;
|
||||
import com.kamco.cd.training.common.enums.TrainType;
|
||||
import com.kamco.cd.training.common.utils.HeaderUtil;
|
||||
import com.kamco.cd.training.common.utils.interfaces.JsonFormatDttm;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -260,7 +261,9 @@ public class ModelTrainMngDto {
|
||||
public String getStatusName() {
|
||||
if (this.statusCd == null || this.statusCd.isBlank()) return null;
|
||||
try {
|
||||
return TrainStatusType.valueOf(this.statusCd).getText(); // 또는 getName()
|
||||
return HeaderUtil.isEnglishRequest()
|
||||
? TrainStatusType.valueOf(this.statusCd).getId()
|
||||
: TrainStatusType.valueOf(this.statusCd).getText(); // 또는 getName()
|
||||
} catch (IllegalArgumentException e) {
|
||||
return this.statusCd; // 매핑 못하면 코드 그대로 반환(원하면 null 처리)
|
||||
}
|
||||
@@ -269,7 +272,9 @@ public class ModelTrainMngDto {
|
||||
public String getStep1StatusName() {
|
||||
if (this.step1Status == null || this.step1Status.isBlank()) return null;
|
||||
try {
|
||||
return TrainStatusType.valueOf(this.step1Status).getText(); // 또는 getName()
|
||||
return HeaderUtil.isEnglishRequest()
|
||||
? TrainStatusType.valueOf(this.step1Status).getId()
|
||||
: TrainStatusType.valueOf(this.step1Status).getText(); // 또는 getName()
|
||||
} catch (IllegalArgumentException e) {
|
||||
return this.step1Status; // 매핑 못하면 코드 그대로 반환(원하면 null 처리)
|
||||
}
|
||||
@@ -278,7 +283,9 @@ public class ModelTrainMngDto {
|
||||
public String getStep2StatusName() {
|
||||
if (this.step2Status == null || this.step2Status.isBlank()) return null;
|
||||
try {
|
||||
return TrainStatusType.valueOf(this.step2Status).getText(); // 또는 getName()
|
||||
return HeaderUtil.isEnglishRequest()
|
||||
? TrainStatusType.valueOf(this.step2Status).getId()
|
||||
: TrainStatusType.valueOf(this.step2Status).getText(); // 또는 getName()
|
||||
} catch (IllegalArgumentException e) {
|
||||
return this.step2Status; // 매핑 못하면 코드 그대로 반환(원하면 null 처리)
|
||||
}
|
||||
@@ -287,7 +294,9 @@ public class ModelTrainMngDto {
|
||||
public String getTrainTypeName() {
|
||||
if (this.trainType == null || this.trainType.isBlank()) return null;
|
||||
try {
|
||||
return TrainType.valueOf(this.trainType).getText(); // 또는 getName()
|
||||
return HeaderUtil.isEnglishRequest()
|
||||
? TrainType.valueOf(this.trainType).getId()
|
||||
: TrainType.valueOf(this.trainType).getText(); // 또는 getName()
|
||||
} catch (IllegalArgumentException e) {
|
||||
return this.trainType; // 매핑 못하면 코드 그대로 반환(원하면 null 처리)
|
||||
}
|
||||
@@ -304,7 +313,11 @@ public class ModelTrainMngDto {
|
||||
long minutes = (totalSeconds % 3600) / 60;
|
||||
long seconds = totalSeconds % 60;
|
||||
|
||||
return String.format("%d시간 %d분 %d초", hours, minutes, seconds);
|
||||
if (HeaderUtil.isEnglishRequest()) {
|
||||
return String.format("%dh %dm %ds", hours, minutes, seconds);
|
||||
} else {
|
||||
return String.format("%d시간 %d분 %d초", hours, minutes, seconds);
|
||||
}
|
||||
}
|
||||
|
||||
public String getStep1Duration() {
|
||||
|
||||
Reference in New Issue
Block a user