Hello, I work on a project based on Kotlin Compose...
# multiplatform
o
Hello, I work on a project based on Kotlin Compose Multiplatform which should be potentially available worldwide at least on Android and iOS (and maybe Desktop). A basic requirement for me is to be able to localize date, currency and number formats according to the country code. I already had a look at the documentation, but did not find a solution. Thank you for your help!
e
kotlinx-datetime doesn't handle localization. you'll need to use each platform's APIs for that
o
Thank you, I will implement with platform APIs then, just hoped there would be a standard solution …
e
there is no standard cross-platform locale right now, so it's kind of hard to do cross-platform localization
you need more than country code to do localization. there are countries with multiple languages, languages with multiple scripts, and currencies are not always connected to either…
o
yes, I know. I already worked on a native iOS app with this all. Fortunately Apple provides localzation functionality …
r
You can still do localization manually up to some point, for example:
Copy code
LocalDateTime.Format {
    dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED)
    char(',')
    char(' ')
    monthName(MonthNames.ENGLISH_ABBREVIATED)
    ...
}
for non-english strings, you can construct your own day of week names and month names, i.e.
Copy code
val SloveneDayOfWeekNames = DayOfWeekNames(
    monday = "Pon",
    tuesday = "Tor",
    wednesday = "Sre",
    thursday = "Čet",
    friday = "Pet",
    saturday = "Sob",
    sunday = "Ned",
)
It may or may not be easier than using platform defaults, depending on your use-case.
e
that's not how it works in all languages though
r
of course, as I said, doing it manually may or may not be easier/"cleaner" than converting a date to a platform type and formatting it there, depending on your use case 🙂