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

[Android] Using a well-formed IETF language tags instead of debug string #40

Merged
merged 2 commits into from
May 7, 2022

Conversation

proninyaroslav
Copy link
Contributor

@proninyaroslav proninyaroslav commented Mar 15, 2022

Changes description

This PR replaces all Locale#toString() with Locale#toLanguageTag() for Android 5.0 and above.

Reason for changes

The plugin returns a debug string instead of a locale tag. For example, instead of zh_Hant_TW (lang_script_country) we got zh_TW_#Hant (lang_country_#script). This is contrary to the Dart locale tag format. Dart and intl package uses IETF BCP 47 format and IANA Language Subtag Registry to determine locale: https://api.flutter.dev/flutter/dart-ui/Locale-class.html.
When passing a string like zh_TW_#Hant instead of zh_Hant_TW to the intl.Locale.parse we got a FormatException.

The documentation for Android Locale#toString() says:

Returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below:
language + "_" + country + "_" + (variant + "_#" | "#") + script + "-" + extensions

This behavior is designed to support debugging and to be compatible with previous uses of toString that expected language, country, and variant fields only. To represent a Locale as a String for interchange purposes, use toLanguageTag().

instead of it, the Locale#toLanguageTag() says:

Returns a well-formed IETF BCP 47 language tag representing this locale.

proninyaroslav added a commit to proninyaroslav/blink-comparison that referenced this pull request Mar 15, 2022
@proninyaroslav
Copy link
Contributor Author

@magnatronus
Can you take a look at this?

@proninyaroslav
Copy link
Contributor Author

@magnatronus
Please merge this PR

@magnatronus
Copy link
Owner

Hi, I am not in a position to check and do the PR currently. As soon as I am I will take a look.

@magnatronus magnatronus merged commit c7f42fc into magnatronus:master May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants