Skip to content

Bug 2085210 - Simplify String.toLocale() and handle complex BCP-47 language tags - #411

Closed
mcarare wants to merge 1 commit into
mozilla-firefox:autolandfrom
mcarare:2085210
Closed

mcarare wants to merge 1 commit into
mozilla-firefox:autolandfrom
mcarare:2085210

Conversation

@mcarare

@mcarare mcarare commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Replaces custom string-splitting in String.toLocale() by normalizing underscores to hyphens and delegating to Locale.forLanguageTag(). This ensures language tags containing scripts, variants, or Unicode extensions are properly parsed, and returns Locale.ROOT for blank input strings.


Lando: link
Bugzilla: bug 2085210

⚠️ This pull request has 2 warnings.
🚫 This pull request has 1 blocker.

@github-actions
github-actions Bot changed the base branch from main to autoland October 23, 2026 07:37
@github-actions

Copy link
Copy Markdown
Contributor

Warning

The target branch has been automatically set to autoland.

Please Edit this PR if this wasn't your intention.

@lando-web
lando-web Bot requested a review from a team October 23, 2026 07:37
@mcarare
mcarare requested a balanced review from Copilot October 23, 2026 07:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation is straightforward, with only a non-blocking test-coverage improvement remaining.

1 open issue
What changed in this PR

Simplifies Android Components’ String.toLocale() helper by delegating language-tag parsing to the platform, supporting complex BCP-47 tags without custom splitting.

Changes:

  • Normalizes underscores to hyphens and uses Locale.forLanguageTag().
  • Explicitly returns Locale.ROOT for blank input and documents supported formats.
  • Adds tests for language, region, script, Unicode-extension, and blank-input cases.
File Description
mobile/​android/​android-components/​components/​support/​locale/​src/​test/​java/​mozilla/​components/​support/​locale/​ExtensionsTest.kt Adds locale-conversion tests.
mobile/​android/​android-components/​components/​support/​locale/​src/​main/​java/​mozilla/​components/​support/​locale/​Extensions.kt Simplifies parsing and documents locale handling.

Review effort: Balanced

…language tags

Replaces custom string-splitting in `String.toLocale()` by normalizing underscores to hyphens and delegating to `Locale.forLanguageTag()`. This ensures language tags containing scripts, variants, or Unicode extensions are properly parsed, and returns `Locale.ROOT` for blank input strings.
@mozilla-code-review

Copy link
Copy Markdown

No new issues detected. This pull request is 🆗

@pollym pollym left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable!
i can't reproduce the crash but looking at the code it seems like this is safer to try and normalise invalid locales rather than crashing. the unit tests fail without the new change. thanks for the fix!

@mcarare
mcarare requested a balanced review from Copilot October 26, 2026 12:20
@lando-web
lando-web Bot requested a review from a team October 26, 2026 12:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review found no blocking issues in this narrow parsing change or its regression tests; tests were not run.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@mcarare
mcarare requested review from pollym and removed request for a team October 26, 2026 13:46
@lando-web
lando-web Bot requested a review from a team October 26, 2026 13:47
lando-worker Bot pushed a commit that referenced this pull request Oct 26, 2026
…language tags r=pollymce

Replaces custom string-splitting in `String.toLocale()` by normalizing underscores to hyphens and delegating to `Locale.forLanguageTag()`. This ensures language tags containing scripts, variants, or Unicode extensions are properly parsed, and returns `Locale.ROOT` for blank input strings.

Pull request: #411
@lando-worker

lando-worker Bot commented Oct 26, 2026

Copy link
Copy Markdown

Pull request closed by commit f1d204e

@lando-worker lando-worker Bot closed this Oct 26, 2026
lando-worker Bot pushed a commit that referenced this pull request Oct 27, 2026
…language tags a=dmeehan

Replaces custom string-splitting in `String.toLocale()` by normalizing underscores to hyphens and delegating to `Locale.forLanguageTag()`. This ensures language tags containing scripts, variants, or Unicode extensions are properly parsed, and returns `Locale.ROOT` for blank input strings.

Pull request: #411

Differential Revision: https://phabricator.services.mozilla.com/D337099
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants