-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from YAPP-Github/feature/DRAW-357
DRAW-357 i18n 버그 수정
- Loading branch information
Showing
15 changed files
with
106 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
app/support/exception/src/main/resources/application-exception.yml
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import org.springframework.boot.gradle.tasks.bundling.BootJar | ||
|
||
plugins { | ||
id("org.springframework.boot") | ||
kotlin("plugin.spring") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":domain")) | ||
implementation(project(":support:logging")) | ||
implementation(project(":support:yaml")) | ||
|
||
implementation("org.springframework.boot:spring-boot-starter:${Versions.SPRING_BOOT}") | ||
} | ||
|
||
tasks { | ||
withType<Jar> { enabled = true } | ||
withType<BootJar> { enabled = false } | ||
} |
30 changes: 30 additions & 0 deletions
30
app/support/i18n/src/main/kotlin/com/xorker/draw/i18n/MessageConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.xorker.draw.i18n | ||
|
||
import org.springframework.context.MessageSource | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.support.ResourceBundleMessageSource | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver | ||
import org.springframework.core.io.support.ResourcePatternResolver | ||
|
||
@Configuration | ||
class MessageConfig { | ||
|
||
@Bean | ||
fun messageSource(): MessageSource { | ||
val resolver: ResourcePatternResolver = PathMatchingResourcePatternResolver() | ||
val resources = resolver.getResources("classpath*:i18n/*") | ||
|
||
val basename = resources | ||
.mapNotNull { it.filename } | ||
.map { "i18n/${it.substring(0, it.lastIndexOf('_'))}" } | ||
.distinct() | ||
.toTypedArray() | ||
|
||
val messageSource = ResourceBundleMessageSource() | ||
messageSource.setDefaultEncoding("UTF-8") | ||
messageSource.setBasenames(*basename) | ||
|
||
return messageSource | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/support/i18n/src/main/kotlin/com/xorker/draw/i18n/MessageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.xorker.draw.i18n | ||
|
||
import com.xorker.draw.exception.NotDefinedMessageCodeException | ||
import com.xorker.draw.support.logging.logger | ||
import java.util.Locale | ||
import org.springframework.context.MessageSource | ||
import org.springframework.context.NoSuchMessageException | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class MessageService( | ||
private val messageSource: MessageSource, | ||
) { | ||
private val logger = logger() | ||
|
||
fun getMessage(code: String, locale: Locale): String { | ||
try { | ||
return messageSource.getMessage(code, null, locale) | ||
} catch (e: NoSuchMessageException) { | ||
logger.error("i18n Error - $code", e) | ||
throw NotDefinedMessageCodeException(code, locale, e) | ||
} | ||
} | ||
|
||
fun getMessageOrNull(code: String, locale: Locale): String? { | ||
try { | ||
return messageSource.getMessage(code, null, locale) | ||
} catch (e: NoSuchMessageException) { | ||
logger.warn("i18n Error - $code", e) | ||
return null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters