-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Adds semantics locale support for web #171196
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
Conversation
| if (localeForChildren != configProvider.effective.locale) { | ||
| configProvider.updateConfig((SemanticsConfiguration config) { | ||
| config.locale = localeForChildren; | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is to update the locale only if it is different.
As for this diagram, I am starting to think whether just set lang for every div will be easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, I misunderstood this code.
Look at my other comment for a potentially easy way to achieve this on web.
| /// {@macro flutter.widgets.ProxyWidget.child} | ||
| final Widget? child; | ||
|
|
||
| /// Whether this is the main localizations with for that represent the app's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Whether this is the main localizations with for that represent the app's | |
| /// Whether this is the main localizations widget that represent the app's |
| // If this is not application level, we need to explicit mark the | ||
| // semantics subtree with the locale. | ||
| localeForSubtree: widget.isApplicationLevel ? null : widget.locale, | ||
| container: !widget.isApplicationLevel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make it always a container?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason this has to be a container if we set localeForSubtree is to prevent it merge up that end up including sibling renderobject to be under it.
for isApplicationLevel is true, it doesn't set localeForSubtree so no need to force it to container. I will have a follow up pr that adds a dart:ui API to set the application locale directly if isApplicationLevel is set to true
| void _updateLocale() { | ||
| final String locale = semanticsObject.locale?.toString() ?? ''; | ||
| if (locale.isEmpty) { | ||
| removeAttribute('lang'); | ||
| return; | ||
| } | ||
| setAttribute('lang', locale); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do something like this to avoid setting the lang attribute everywhere:
| void _updateLocale() { | |
| final String locale = semanticsObject.locale?.toString() ?? ''; | |
| if (locale.isEmpty) { | |
| removeAttribute('lang'); | |
| return; | |
| } | |
| setAttribute('lang', locale); | |
| } | |
| void _updateLocale() { | |
| final String locale = semanticsObject.locale?.toString() ?? ''; | |
| final isSameAsParent = semanticsObject.locale == semanticsObject.parent?.locale; | |
| if (locale.isEmpty || isSameAsParent) { | |
| removeAttribute('lang'); | |
| return; | |
| } | |
| setAttribute('lang', locale); | |
| } |
| if (localeForChildren != configProvider.effective.locale) { | ||
| configProvider.updateConfig((SemanticsConfiguration config) { | ||
| config.locale = localeForChildren; | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, I misunderstood this code.
Look at my other comment for a potentially easy way to achieve this on web.
hannah-hyj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
autosubmit label was removed for flutter/flutter/171196, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
migrating internal code cl/778235479 Nothing functionally wrong, but internal code relies on implicit merging of semantics tree. Since this pr adds a container to the localization widget, it messes with the implicit merging of customer's app. |
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> toward flutter#98948 This sets the ground work for framework and web still need to implement: 1. Android and iOS support 2. set application locale. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
toward #98948
This sets the ground work for framework and web
still need to implement:
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.