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 Jun 27, 2023
1 parent b5298f0 commit 476eaf5
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Caffeine
import com.tencent.devops.common.api.exception.TurboException
import com.tencent.devops.common.api.exception.code.TURBO_PARAM_INVALID
import com.tencent.devops.common.db.PageUtils
import com.tencent.devops.common.util.I18NUtil
import com.tencent.devops.common.util.enums.ConfigParamType
import com.tencent.devops.turbo.dao.mongotemplate.TurboEngineConfigDao
import com.tencent.devops.turbo.dao.repository.TurboEngineConfigRepository
Expand Down Expand Up @@ -540,14 +541,14 @@ class TurboEngineConfigService @Autowired constructor(
return turboEngineConfigList.map {
TurboEngineConfigVO(
engineCode = it.engineCode,
engineName = it.engineName,
engineName = I18NUtil.getMessage("${it.engineCode}.engineName"),
priorityNum = it.priorityNum,
userManual = it.userManual,
desc = it.desc,
paramConfig = it.paramConfig?.filter { param -> param.displayed }?.map { param ->
ParamConfigModel(
paramKey = param.paramKey,
paramName = param.paramName,
paramName = I18NUtil.getMessage("${it.engineCode}.paramConfig.${param.paramKey}.paramName"),
paramType = param.paramType,
paramProps = param.paramProps,
paramEnum = param.paramEnum?.filter { paramEnumEntity ->
Expand All @@ -556,7 +557,8 @@ class TurboEngineConfigService @Autowired constructor(
}?.map { paramEnumEntity ->
ParamEnumModel(
paramValue = paramEnumEntity.paramValue,
paramName = paramEnumEntity.paramName,
paramName = I18NUtil.getMessage("${it.engineCode}.paramConfig.${param.paramKey
}.paramEnum.${paramEnumEntity.paramValue}"),
visualRange = paramEnumEntity.visualRange
)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
disttask-cc.desc=A brand-new, self-developed engine with zero intrusion and one-click acceleration offers faster speeds. It provides visual compilation charts to clearly control the entire process data. Features include support for PCH, Gcov, distributed preprocessing, and more.
disttask-cc.recommendReason=A brand-new, self-developed engine with zero intrusion and one-click acceleration offers faster speeds. It provides visual compilation charts to clearly control the entire process data. Features include support for PCH, Gcov, distributed preprocessing, and more.
disttask-cc.engineName=Linux-C/C++ Acceleration
disttask-cc.paramConfig.queue_name=Priority Scheduling Area
disttask-cc.paramConfig.queue_name.paramEnum.K8S\://gd=Shenzhen-K8S Cluster
disttask-cc.paramConfig.queue_name.paramEnum.shenzhen=Shenzhen/Guangzhou
disttask-cc.paramConfig.queue_name.paramEnum.shanghai=Shanghai/Nanjing
disttask-cc.paramConfig.queue_name.paramEnum.chengdu=Chengdu/Chongqing
disttask-cc.paramConfig.queue_name.paramEnum.tianjin=Beijing/Tianjin
disttask-cc.paramConfig.worker_version.paramName=Builder Version
disttask-cc.paramConfig.ccache_enabled.paramName=Enable Ccache

disttask-ue4.desc=A self-developed engine for accelerating Unreal Engine builds across multiple platforms. Supports acceleration for Editor, Shader, Dedicated Servers, and more.
disttask-ue4.recommendReason=A self-developed engine for accelerating Unreal Engine builds across multiple platforms. Supports acceleration for Editor, Shader, Dedicated Servers, and more.
disttask-ue4.engineName=Unreal Engine Acceleration
disttask-ue4.paramConfig.worker_version.paramName=Build Environment
disttask-ue4.paramConfig.worker_version.paramEnum.win2019-pure-drived=Windows General Environment
disttask-ue4.paramConfig.worker_version.paramEnum.macvm=MacOS General Environment
disttask-ue4.paramConfig.worker_version.paramEnum.tlinux2.2-generic=TLinux2.2 General Environment
disttask-ue4.paramConfig.queue_name=Acceleration Platform

distcc.desc=【Deprecated】Traditional distcc approach, suitable for C/C++ compilation under Linux.
distcc.engineName=distcc
distcc.paramConfig.city.paramName=Priority Scheduling Area
distcc.paramConfig.city.paramEnum.K8S\://gd=Shenzhen-K8S Cluster
distcc.paramConfig.city.paramEnum.shenzhen=Shenzhen/Guangzhou
distcc.paramConfig.city.paramEnum.shanghai=Shanghai/Nanjing
distcc.paramConfig.city.paramEnum.chengdu=Chengdu/Chongqing
distcc.paramConfig.city.paramEnum.tianjin=Beijing/Tianjin
distcc.paramConfig.gcc_version.paramName=Builder Version
distcc.paramConfig.ccache_enabled.paramName=Enable Ccache

disttask-cc.displayFields.queue_name.fieldName=Acceleration Zone
disttask-cc.displayFields.request_cpu.fieldName=Acceleration CPU Core
disttask-cc.displayFields.worker_version.fieldName=Work Version
disttask-cc.displayFields.client_version.fieldName=Client Version
disttask-cc.displayFields.client_ip.fieldName=Initiating Node
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
disttask-cc.desc=全新自研引擎,零侵入一键加速,更快的速度,提供可视化编译图表,清晰掌控全流程数据。支持pch、gcov、分布式预处理等更多功能。
disttask-cc.recommendReason=全新自研引擎,零侵入一键加速,更快的速度,提供可视化编译图表,清晰掌控全流程数据。支持pch、gcov、分布式预处理等更多功能。
disttask-cc.engineName=Linux-C/C++ 加速
disttask-cc.paramConfig.queue_name.paramName=优先调度区域
disttask-cc.paramConfig.queue_name.paramEnum.K8S\://gd=深圳K8S集群(推荐)
disttask-cc.paramConfig.queue_name.paramEnum.shenzhen=深圳/广州
disttask-cc.paramConfig.queue_name.paramEnum.shanghai=上海/南京
disttask-cc.paramConfig.queue_name.paramEnum.chengdu=成都/重庆
disttask-cc.paramConfig.queue_name.paramEnum.tianjin=北京/天津
disttask-cc.paramConfig.worker_version.paramName=编译器版本
disttask-cc.paramConfig.ccache_enabled.paramName=是否启用Ccache

disttask-ue4.desc=自研引擎,多平台下的 UE4 构建加速。支持 Editor、Shader、Dedicated Servers 等加速。
disttask-ue4.recommendReason=自研引擎,多平台下的 UE4 构建加速。支持 Editor、Shader、Dedicated Servers 等加速。
disttask-ue4.engineName=UE4加速
disttask-ue4.paramConfig.worker_version.paramName=编译环境
disttask-ue4.paramConfig.worker_version.paramEnum.win2019-pure-drived=Windows通用环境
disttask-ue4.paramConfig.worker_version.paramEnum.macvm=Mac通用环境
disttask-ue4.paramConfig.worker_version.paramEnum.tlinux2.2-generic=TLinux2.2通用环境
disttask-ue4.paramConfig.queue_name=加速平台

distcc.desc=【旧版本】传统distcc方案, 适用于linux下的c/c++编译
distcc.engineName=distcc
distcc.paramConfig.city.paramName=优先调度区域
distcc.paramConfig.city.paramEnum.K8S\://gd=深圳K8S集群(推荐)
distcc.paramConfig.city.paramEnum.shenzhen=深圳/广州
distcc.paramConfig.city.paramEnum.shanghai=上海/南京
distcc.paramConfig.city.paramEnum.chengdu=成都/重庆
distcc.paramConfig.city.paramEnum.tianjin=北京/天津
distcc.paramConfig.gcc_version.paramName=编译器版本
distcc.paramConfig.ccache_enabled.paramName=是否启用Ccache

displayFields.queue_name.fieldName=加速集群地区
displayFields.request_cpu.fieldName=加速资源
displayFields.worker_version.fieldName=Worker 版本
displayFields.client_version.fieldName=Client 版本
displayFields.client_ip.fieldName=发起机器 IP
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.tencent.devops.common.util

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.MessageSource
import org.springframework.context.i18n.LocaleContextHolder
import org.springframework.stereotype.Component
import java.util.Locale

@Component
object I18NUtil {

@JvmStatic
lateinit var messageSource: MessageSource
@Autowired set


@JvmStatic
fun getMessage(code: String): String {
return getMessage(code, null)
}

@JvmStatic
fun getMessage(code: String, args: Array<Any>?): String {
return getMessage(code, args, LocaleContextHolder.getLocale())
}

@JvmStatic
fun getMessage(code: String, args: Array<Any>?, locale: Locale): String {
return messageSource.getMessage(code, args, locale)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ package com.tencent.devops.common.web.config
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer
import com.tencent.devops.common.web.interceptor.LocaleInterceptor
import com.tencent.devops.common.web.jasypt.DefaultEncryptor
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.MessageSource
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import org.springframework.context.support.ResourceBundleMessageSource
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import java.nio.charset.StandardCharsets
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter


@Suppress("MaxLineLength")
@Configuration
class WebAutoConfiguration : WebMvcConfigurer {
Expand All @@ -22,6 +28,16 @@ class WebAutoConfiguration : WebMvcConfigurer {
@Primary
fun stringEncryptor(@Value("\${enc.key:rAFOey00bcuMNMrt}") key: String) = DefaultEncryptor(key)

@Bean("messageSource")
fun messageSource(): MessageSource {
val messageSource = ResourceBundleMessageSource()
messageSource.setBasename("i18n/message")
messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name())
// 缓存6小时
messageSource.setCacheSeconds(3600 * 6)
return messageSource
}

override fun configureMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
converters.forEach {
if (it is MappingJackson2HttpMessageConverter) {
Expand All @@ -33,4 +49,8 @@ class WebAutoConfiguration : WebMvcConfigurer {
}
super.configureMessageConverters(converters)
}

override fun addInterceptors(registry: InterceptorRegistry) {
registry.addInterceptor(LocaleInterceptor())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.tencent.devops.common.web.interceptor

import org.springframework.context.i18n.LocaleContextHolder
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import java.util.Locale
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@Component
class LocaleInterceptor : HandlerInterceptor {

override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
val acceptLanguage = request.getHeader("Accept-Language")
val parameterLocale = request.getParameter("locale")
val locale = parseLocale(acceptLanguage, parameterLocale)
LocaleContextHolder.setLocale(locale)

return true
}

private fun parseLocale(acceptLanguage: String?, paramLocale: String?): Locale {
if (!acceptLanguage.isNullOrBlank()) {
val languageTag = acceptLanguage.split(",")[0].trim()
return Locale.forLanguageTag(languageTag)
}

if (!paramLocale.isNullOrBlank()) {
return genLocale(paramLocale)
}

return Locale.getDefault()
}

private fun genLocale(requestParameter: String): Locale {
val splitArr = if (requestParameter.contains("-")) {
requestParameter.split("-")
} else {
requestParameter.split("_")
}
return Locale(splitArr[0], splitArr[1])
}
}

0 comments on commit 476eaf5

Please sign in to comment.