Skip to content

fix: Format Locale objects scriptcode correctly#773

Merged
PartyDonut merged 2 commits intoDonutWare:developfrom
d0gkiller87:fix/Locale-toDisplayCode
Feb 20, 2026
Merged

fix: Format Locale objects scriptcode correctly#773
PartyDonut merged 2 commits intoDonutWare:developfrom
d0gkiller87:fix/Locale-toDisplayCode

Conversation

@d0gkiller87
Copy link
Copy Markdown
Contributor

Pull Request Description

The existing logic for:

Doesn't take Locale.scriptCode into account during formatting/serialization, turning language codes like zh_Hant into zh. This PR addresses the issue and formats/parses language codes according to the pattern of BCP 47. (i.e. EN_USen_US, ZH_HANTzh_Hant)

Issue Being Fixed

Resolves #641

Checklist

  • If a new package was added, did you ensure it works for all supported platforms? Is the package well maintained
  • Check that any changes are related to the issue at hand.

@d0gkiller87
Copy link
Copy Markdown
Contributor Author

One thing to note: since the original implementation already saves language codes in BCP 47's format, existing users' selected language won't be affected by this change as tested by migrating from version 9.0.

Copy link
Copy Markdown
Collaborator

@PartyDonut PartyDonut left a comment

Choose a reason for hiding this comment

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

Looks good to me, small change request just to make sure.

@d0gkiller87
Copy link
Copy Markdown
Contributor Author

d0gkiller87 commented Feb 18, 2026

Another thing before merging:
Not sure how localeResolutionCallback (pointed out by @kikibase @ a0182ef) affects the locale loading process. In my test runs, taking care of scriptCode already mitigated the issue. Can someone check what localeResolutionCallback actually does in Fladder?

@d0gkiller87
Copy link
Copy Markdown
Contributor Author

Another thing before merging: Not sure how localeResolutionCallback (pointed out by @kikibase @ a0182ef) affects the locale loading process. In my test runs, taking care of scriptCode already mitigated the issue. Can someone check what localeResolutionCallback actually does in Fladder?

Never mind, I understand it now.

For reference, the code in question:
https://github.com/DonutWare/Fladder/blob/v0.9.0/lib/main.dart#L321

It defines both locale and localeResolutionCallback. According to the Flutter documentation: https://api.flutter.dev/flutter/widgets/WidgetsApp/locale.html

localeResolutionCallback, which can override the default supportedLocales matching algorithm.

And given this block:

if (supportedLocales.contains(locale)) {
  return locale;
}

the (l) => l.languageCode == locale.languageCode check effectively serves as a fallback. It only runs when locale is not found in supportedLocales.

If we were changing it to (l) => l == locale, it would likely never match, since supportedLocales.contains(locale) has already failed at that point ...

If everything checks out, please feel free to merge the PR, thanks!

@PartyDonut PartyDonut added the bug Something isn't working label Feb 20, 2026
@github-project-automation github-project-automation bot moved this to In Progress in Fladder Feb 20, 2026
@PartyDonut PartyDonut changed the title fix: Format Locale objects correctly (#641) fix: Format Locale objects correctly Feb 20, 2026
@PartyDonut PartyDonut changed the title fix: Format Locale objects correctly fix: Format Locale objects scriptcode correctly Feb 20, 2026
@PartyDonut PartyDonut merged commit bcca852 into DonutWare:develop Feb 20, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Fladder Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 After selecting the Traditional Chinese language, restarting will revert to the Simplified Chinese language

2 participants