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

Multiplatform Locale #5416

Open
westnordost opened this issue Dec 20, 2023 · 1 comment
Open

Multiplatform Locale #5416

westnordost opened this issue Dec 20, 2023 · 1 comment
Labels
blocked blocked by another issue iOS necessary for iOS port

Comments

@westnordost
Copy link
Member

Requires #5412.

Java java.util.Locale is currently used in various places, most of them in the UI. Features used are (non-exhaustive list):

  • access language code, country code and script code of user's locale

  • access the display names of languages, countries and scripts in the user's locale

  • to correctly upper-, lower- and titlecase words

  • to correctly format decimals (e.g. in German, decimals are separated by a comma from the number, not a point)

  • to set the app's locale and the map's locale to whatever has been set by the language selector

And also:

  • get the localized names of months and weekdays (using java.text.DateFormatSymbols) (for monthday and weekday picker)

  • format time correctly (using java.text.DateFormat / java.time.format.DateTimeFormatter) (for wherever a time is displayed)

This functionality must be replaced with something that works on multiplatform.

Migration

In some places, Locale is just used as a key in a map or something. These could be just replaced by a string, i.e. the IETF BCP 47 language tag (e.g. "de-DE") to remove any dependency to any sort of specific Locale implementation.

NSLocale

The iOS equivalent of java.util.Locale is NSLocale. On first glance, it has all the features that the Java version has. So, a simple actual / expect implementation may be possible.

multiplatform-locale

There is one multiplatform library that already does the wrapping: https://github.com/vanniktech/multiplatform-locale

However, at the time of writing, it is very fresh, so there are no guarantees about stability, continuous maintenance of the library etc. Additionally, it may have many features that we don't need while lacking others that we may need.

Date and time format

We are using kotlinx-datetime for anything date/time-related (as a replacement for Java 8 Date/Time classes). However, this library is missing any (locale-aware) formatting of these. Though it is planned to add support for formatting dates and times in the next major release 0.6.0 (see Kotlin/kotlinx-datetime#251), this is still not the Java locale-aware date/time formatting.

The iOS equivalent of date formatting is NSDateFormatter, so at the time of writing, a simple actual / expect implementation may be possible.

@westnordost westnordost added iOS necessary for iOS port blocked blocked by another issue labels Dec 20, 2023
@westnordost westnordost moved this to Blocked in iOS Port Dec 20, 2023
@westnordost
Copy link
Member Author

Ticket about locale-aware formatting of date/time in kotlinx-datetime: Kotlin/kotlinx-datetime#352

It is on the roadmap, but until 0.9.0 it will be quite a while it seems. Don't think it would make sense to wait for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked blocked by another issue iOS necessary for iOS port
Projects
Status: Blocked
Development

No branches or pull requests

1 participant