-
Notifications
You must be signed in to change notification settings - Fork 0
[REFACTOR/#283] 하드코딩된 문자열 리소스를 추출하여 i18n 적용 준비 합니다. #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
11a25f7
2811b7c
30a6366
f160c3e
9b8a3b6
a751473
5f0ae0f
723333e
b2b5aec
9ea1338
d3a549c
05a5d8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,26 +17,64 @@ import androidx.compose.ui.unit.dp | |
| import com.sopt.clody.ui.theme.ClodyTheme | ||
| import kotlinx.datetime.DayOfWeek | ||
|
|
||
| enum class WeekLang { | ||
| KOREAN, ENGLISH | ||
| } | ||
|
|
||
| fun DayOfWeek.toKoreanShortLabel(): String { | ||
| return when (this) { | ||
| DayOfWeek.SUNDAY -> "일" | ||
| DayOfWeek.MONDAY -> "월" | ||
| DayOfWeek.TUESDAY -> "화" | ||
| DayOfWeek.WEDNESDAY -> "수" | ||
| DayOfWeek.THURSDAY -> "목" | ||
| DayOfWeek.FRIDAY -> "금" | ||
| DayOfWeek.SATURDAY -> "토" | ||
| } | ||
| } | ||
|
|
||
| fun DayOfWeek.toEnglishShortLabel(): String { | ||
| return when (this) { | ||
| DayOfWeek.SUNDAY -> "Sun" | ||
| DayOfWeek.MONDAY -> "Mon" | ||
| DayOfWeek.TUESDAY -> "Tue" | ||
| DayOfWeek.WEDNESDAY -> "Wed" | ||
| DayOfWeek.THURSDAY -> "Thu" | ||
| DayOfWeek.FRIDAY -> "Fri" | ||
| DayOfWeek.SATURDAY -> "Sat" | ||
| } | ||
| } | ||
|
|
||
| fun DayOfWeek.getLabel(lang: WeekLang): String { | ||
| return when (lang) { | ||
| WeekLang.KOREAN -> this.toKoreanShortLabel() | ||
| WeekLang.ENGLISH -> this.toEnglishShortLabel() | ||
| } | ||
| } | ||
|
Comment on lines
+24
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Hardcoded strings violate i18n principles. While the
Replace the hardcoded strings with string resources: fun DayOfWeek.toKoreanShortLabel(): String {
return when (this) {
- DayOfWeek.SUNDAY -> "일"
- DayOfWeek.MONDAY -> "월"
+ DayOfWeek.SUNDAY -> stringResource(R.string.weekday_sunday_short_ko)
+ DayOfWeek.MONDAY -> stringResource(R.string.weekday_monday_short_ko)
// ... continue for all days
}
}Or better yet, consider using a single extension function with
🤖 Prompt for AI Agents |
||
|
|
||
| @Composable | ||
| fun WeekHeader(modifier: Modifier = Modifier, itemWidth: Dp) { | ||
| val itemWidth = (LocalConfiguration.current.screenWidthDp.dp - 40.dp) / 7 | ||
| fun WeekHeader( | ||
| modifier: Modifier = Modifier, | ||
| itemWidth: Dp = (LocalConfiguration.current.screenWidthDp.dp - 40.dp) / 7, | ||
| lang: WeekLang = WeekLang.KOREAN, | ||
| ) { | ||
| val weekLabelArray = listOf( | ||
| DayOfWeek.SUNDAY, | ||
| DayOfWeek.MONDAY, | ||
| DayOfWeek.TUESDAY, | ||
| DayOfWeek.WEDNESDAY, | ||
| DayOfWeek.THURSDAY, | ||
| DayOfWeek.FRIDAY, | ||
| DayOfWeek.SATURDAY, | ||
| ) | ||
|
|
||
| val labels = weekLabelArray.map { it.getLabel(lang) } | ||
|
|
||
| Row( | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| modifier = modifier.fillMaxWidth(), | ||
| ) { | ||
| val weekLabelArray = listOf( | ||
| DayOfWeek.SUNDAY, | ||
| DayOfWeek.MONDAY, | ||
| DayOfWeek.TUESDAY, | ||
| DayOfWeek.WEDNESDAY, | ||
| DayOfWeek.THURSDAY, | ||
| DayOfWeek.FRIDAY, | ||
| DayOfWeek.SATURDAY, | ||
| ) | ||
|
|
||
| val koreanWeekLabels = weekLabelArray.map { it.toKoreanShortLabel() } | ||
|
|
||
| koreanWeekLabels.forEach { week -> | ||
| labels.forEach { week -> | ||
| Box( | ||
| modifier = Modifier.width(itemWidth), | ||
| contentAlignment = Alignment.Center, | ||
|
|
@@ -52,19 +90,14 @@ fun WeekHeader(modifier: Modifier = Modifier, itemWidth: Dp) { | |
| } | ||
| } | ||
|
|
||
| fun DayOfWeek.toKoreanShortLabel(): String { | ||
| return when (this) { | ||
| DayOfWeek.SUNDAY -> "일" | ||
| DayOfWeek.MONDAY -> "월" | ||
| DayOfWeek.TUESDAY -> "화" | ||
| DayOfWeek.WEDNESDAY -> "수" | ||
| DayOfWeek.THURSDAY -> "목" | ||
| DayOfWeek.FRIDAY -> "금" | ||
| DayOfWeek.SATURDAY -> "토" | ||
| } | ||
| @Preview(showBackground = true) | ||
| @Composable | ||
| fun WeekHeaderKoreanPreview() { | ||
| WeekHeader(lang = WeekLang.KOREAN) | ||
| } | ||
|
|
||
| @Composable | ||
| @Preview(showBackground = true) | ||
| fun WeekHeaderPreview() { | ||
| @Composable | ||
| fun WeekHeaderEnglishPreview() { | ||
| WeekHeader(lang = WeekLang.ENGLISH) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[p4]
스트링 추출 후에 다국어 지원으로 가는 방향이 아니라 이 방식으로 진행한 이유가 따로 있나요?
한국어, 한자, 영어를 제외하고 다른 방법 쓸 일이 있을까 싶긴한데 다국어 관련해서 추가 사항이 있으면 항상 이렇게 따로 추가해야 하는게 번거로울 수도 있지 않을까하는 생각이 드네요. 스트링 추출해서 언어 지원을 바꾸는 걸로 전부 대응하려는게 너무 딸깍적 사고일까요 ㅋㅋ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
딱히 특별한 이유는 없고, EN/KR 두 가지 label만 가볍게 다룰 목적이었습니다.
중국어나 일본어 같은 건 고려하지 않았고, 기존 구조가
toKoreanShortLabel()함수를 이미 사용하고 있어서 영어만 extension으로 자연스럽게 추가한 형태입니다.