Skip to content

Commit

Permalink
feat: turbo后台信息国际化 TencentBlueKing#86
Browse files Browse the repository at this point in the history
  • Loading branch information
eazence committed Jul 12, 2023
1 parent 5e0d7cd commit 98ecbb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ class TurboRecordService @Autowired constructor(
fun getTurboRecordDisplayInfo(turboRecordEntity: TTurboRecordEntity, turboPlanEntity: TTurboPlanEntity): TurboRecordDisplayVO {
val displayFields = mutableListOf(
TurboDisplayFieldVO(
fieldName = I18NUtil.getMessage("displayFields.taskId")!!,
fieldName = I18NUtil.getMessage("displayFields.taskId"),
fieldValue = turboRecordEntity.id!!
),
TurboDisplayFieldVO(
fieldName = I18NUtil.getMessage("displayFields.plan")!!,
fieldName = I18NUtil.getMessage("displayFields.plan"),
fieldValue = turboPlanEntity.planName,
link = true,
linkAddress = "$devopRootPath/console/turbo/${turboPlanEntity.projectId}/task/detail/${turboRecordEntity.turboPlanId!!}"
Expand Down Expand Up @@ -351,17 +351,17 @@ class TurboRecordService @Autowired constructor(
// val displayFieldValue = (paramConfigMap[it.fieldKey]?.get(displayRange[it.fieldKey].toString())) ?: displayRange[it.fieldKey]
val paramEnumMap = paramConfigMap[it.fieldKey]
val displayFieldValue = if (null != paramEnumMap) {
logger.info("paramEnumMap: ${JsonUtil.toJson(paramEnumMap)} \n i18n key: ${turboEngineConfigEntity
.engineCode}.paramConfig.${it.fieldKey}.paramEnum.${displayRange[it.fieldKey].toString()}")
I18NUtil.getMessage("${turboEngineConfigEntity.engineCode}.paramConfig.${it.fieldKey
}.paramEnum.${displayRange[it.fieldKey].toString()}") ?: displayRange[it.fieldKey]
val i18nCode = "${turboEngineConfigEntity.engineCode}.paramConfig.${it.fieldKey
}.paramEnum.${displayRange[it.fieldKey].toString()}"
val fieldValue = I18NUtil.getMessage(i18nCode)
if (I18NUtil.ERROR != fieldValue) fieldValue else displayRange[it.fieldKey]
} else {
displayRange[it.fieldKey]
}

displayFields.add(
TurboDisplayFieldVO(
fieldName = I18NUtil.getMessage("displayFields.${it.fieldKey}.fieldName") ?: it.fieldName,
fieldName = I18NUtil.getMessage("displayFields.${it.fieldKey}.fieldName"),
fieldValue = displayFieldValue,
link = it.link,
linkAddress = if (it.link == true && !it.linkTemplate.isNullOrBlank()) {
Expand All @@ -382,7 +382,7 @@ class TurboRecordService @Autowired constructor(
if (!turboRecordEntity.pipelineName.isNullOrBlank()) {
displayFields.add(
TurboDisplayFieldVO(
fieldName = I18NUtil.getMessage("displayFields.pipeline")!!,
fieldName = I18NUtil.getMessage("displayFields.pipeline"),
fieldValue = turboRecordEntity.pipelineName,
link = true,
linkAddress = "$devopRootPath/console/pipeline/${turboPlanEntity.projectId}/${turboRecordEntity.pipelineId}/detail/${turboRecordEntity.devopsBuildId}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import java.util.Locale

object I18NUtil {

const val ERROR: String = "i18n error"

fun getMessage(code: String): String {
return getMessage(code, null)
}
Expand All @@ -21,7 +23,7 @@ object I18NUtil {
return try {
messageSource.getMessage(code, args, locale)
} catch (_: NoSuchMessageException) {
"i18n error"
ERROR
}
}
}

0 comments on commit 98ecbb8

Please sign in to comment.