feat: Get platform locale info and listen to its changes#6191
Open
ndonkoHenri wants to merge 9 commits intomainfrom
Open
feat: Get platform locale info and listen to its changes#6191ndonkoHenri wants to merge 9 commits intomainfrom
ndonkoHenri wants to merge 9 commits intomainfrom
Conversation
Deploying flet-docs with
|
| Latest commit: |
a51cff0
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1f610ac8.flet-docs.pages.dev |
| Branch Preview URL: | https://get-device-locales.flet-docs.pages.dev |
Deploying flet-examples with
|
| Latest commit: |
a51cff0
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b96999d5.flet-examples.pages.dev |
| Branch Preview URL: | https://get-device-locales.flet-examples.pages.dev |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for detecting platform locale information and listening to locale changes in Flet applications, addressing issue #3010. The implementation provides a way to retrieve device locales and react to system language preference changes across all supported platforms.
Changes:
- Added
localesfield to all DeviceInfo classes to expose system locale preferences - Implemented
LocaleChangeEventandon_locale_changehandler for runtime locale change notifications - Added
language_tagproperty and__str__method to the Locale class for better locale string formatting
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/controls/types.py | Added language_tag property, __str__ method, and _raw_to_string helper to Locale class for formatting locale identifiers |
| sdk/python/packages/flet/src/flet/controls/page.py | Added LocaleChangeEvent dataclass and on_locale_change event handler to Page class |
| sdk/python/packages/flet/src/flet/controls/device_info.py | Added required locales field to all DeviceInfo classes; changed to kw_only=True dataclasses; fixed typo in Windows build lab example (though incorrectly changed) |
| sdk/python/packages/flet/src/flet/init.py | Exported LocaleChangeEvent class |
| sdk/python/packages/flet/mkdocs.yml | Added LocaleChangeEvent to documentation navigation |
| sdk/python/packages/flet/docs/types/localechangeevent.md | Added documentation page for LocaleChangeEvent |
| sdk/python/packages/flet/docs/controls/page.md | Added reference to device locale example |
| sdk/python/examples/controls/page/device_locale.py | Added example demonstrating locale retrieval and change detection |
| packages/flet/lib/src/utils/locale.dart | Added toMap() method to serialize Locale for transmission to Python |
| packages/flet/lib/src/utils/device_info.dart | Added getDeviceLocales() function and included locales in device info for all platforms |
| packages/flet/lib/src/controls/page.dart | Implemented didChangeLocales lifecycle method with deduplication to trigger locale change events |
| .gitignore | Added .fvm/ for Flutter Version Management |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3010
Test Code
Summary by Sourcery
Add support for accessing platform locale preferences and reacting to locale changes across Flutter and Python APIs.
New Features:
Enhancements:
Documentation: