Skip to content
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

Support Locale in WheelDatePicker #20

Open
easyhooon opened this issue Sep 3, 2024 · 1 comment
Open

Support Locale in WheelDatePicker #20

easyhooon opened this issue Sep 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@easyhooon
Copy link

easyhooon commented Sep 3, 2024

image

As shown in the picture above, with the previous library WheelPickerCompose, we could confirm that the text for the month was applied according to the Locale settings. (Locale.KOREAN applied)

// Screen Component

WheelDatePicker(
                    modifier = Modifier.padding(horizontal = 15.dp),
                    startDate = uiState.mateRecruitDate.parseToLocalDate(),
                    minDate = LocalDate.now(),
                    maxDate = LocalDate.of(2030, 12, 31),
                    rowCount = 5,
                    textStyle = Large20_Mid,
                    textColor = Gray001,
                    selectorProperties = WheelPickerDefaults.selectorProperties(
                        enabled = true,
                        shape = RoundedCornerShape(10.dp),
                        color = Gray010,
                        border = BorderStroke(2.dp, Gray010),
                    ),
                ) { snappedDate -> run { selectedDate = snappedDate.formatToDate() } }

// Utils.kt

import java.time.LocalDate
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.util.Locale
fun LocalDate.formatToDate(): String {
    val formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일", Locale.KOREAN)
    return this.format(formatter)
}

fun String.parseToLocalDate(): LocalDate {
    val formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일", Locale.KOREAN)
    return LocalDate.parse(this, formatter)
}
image

However, in the current library that supports Kotlin Multiplatform, these Locale properties are not applied, causing the month's text to always be displayed in English.

For some reason, the kotlinx-datetime library doesn't seem to support Java.util.Locale provided by Java (I might be mistaken about this), so Locale is not being applied.
Could you possibly explain why this is the case? Also, I'm curious if this is a limitation of Kotlin or the kotlinx-datetime library.

@darkokoa
Copy link
Owner

darkokoa commented Sep 3, 2024

You're right, Locale isn't working for this lib yet. Here's why:

When I migrated the original lib to multiplatform, I didn't include support for localization (L10N). That's why you're seeing month names based on the Month enum instead of localized names.

I originally skipped L10N partly because Kotlin-Datetime didn't have built-in Locale support. So, I decided to put L10N on the back burner for a while.

Long story short, I'm the one who limited the L10N. But I'm actively working on adding proper L10N support soon.

@darkokoa darkokoa added the enhancement New feature or request label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants