오디오 콘텐츠 테마 번역을 적용한다

오디오 콘텐츠 목록 응답에서 테마 문자열에 번역을 적용한다.

번역 데이터가 없을 때는 기존 원문을 유지한다.
This commit is contained in:
2025-12-19 03:23:56 +09:00
parent 31242a1f76
commit 6cc15a8748
2 changed files with 95 additions and 3 deletions

View File

@@ -920,12 +920,34 @@ class AudioContentService(
contentId = audioContent.id!!
)
/**
* themeStr 번역 처리
*/
val themeStrTranslated = run {
val theme = audioContent.theme
if (theme?.id != null) {
val locale = langContext.lang.code
val translated = contentThemeTranslationRepository
.findByContentThemeIdAndLocale(theme.id!!, locale)
val text = translated?.theme
if (!text.isNullOrBlank()) text else theme.theme
} else {
audioContent.theme!!.theme
}
}
return GetAudioContentListItem(
contentId = audioContent.id!!,
coverImageUrl = "$coverImageHost/${audioContent.coverImage}",
title = audioContent.title,
title = run {
val translatedTitle = contentTranslationRepository
.findByContentIdAndLocale(audioContent.id!!, langContext.lang.code)
?.renderedPayload
?.title
if (translatedTitle.isNullOrBlank()) audioContent.title else translatedTitle
},
price = audioContent.price,
themeStr = audioContent.theme!!.theme,
themeStr = themeStrTranslated,
duration = audioContent.duration,
likeCount = likeCount,
commentCount = commentCount,
@@ -1017,9 +1039,42 @@ class AudioContentService(
items
}
// theme 번역 적용: 번역 데이터가 있으면 번역, 없으면 원문 유지
val themeTranslatedList = run {
if (translatedContentList.isEmpty()) {
translatedContentList
} else {
val locale = langContext.lang.code
// 활성 테마 목록에서 한글 원문 -> ID 매핑 구성
val themesWithIds = themeQueryRepository.getActiveThemeWithIdsOfContent(
isAdult = isAdult,
isFree = false,
isPointAvailableOnly = false,
contentType = contentType
)
val idByKorean = themesWithIds.associate { it.theme to it.id }
val themeIds = idByKorean.values.distinct()
val translatedById = if (themeIds.isNotEmpty()) {
contentThemeTranslationRepository
.findByContentThemeIdInAndLocale(themeIds, locale)
.associate { it.contentThemeId to it.theme }
} else {
emptyMap()
}
translatedContentList.map { item ->
val themeId = idByKorean[item.themeStr]
val translated = if (themeId != null) translatedById[themeId] else null
if (!translated.isNullOrBlank()) item.copy(themeStr = translated) else item
}
}
}
return GetAudioContentListResponse(
totalCount = totalCount,
items = translatedContentList
items = themeTranslatedList
)
}