-
Notifications
You must be signed in to change notification settings - Fork 6k
Ensure Platform.localeName isn't '_' #4495
Conversation
| String _localeClosure() => window._locale.toString(); | ||
| String _localeClosure() { | ||
| const String enUS = 'en_US'; | ||
| final String locale = window?._locale?.toString() ?? enUS; |
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.
?. wasn't used before - seems like we could do without them here. If we do need then, then you should check for null below.
| String _localeClosure() { | ||
| const String enUS = 'en_US'; | ||
| final String locale = window?._locale?.toString() ?? enUS; | ||
| return (locale == '_') ? enUS : 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.
Why is it _ in the first place versus just being null or the empty string? Are the tests that failed valid in wanting it to start out as _?
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 Locale is initialized from the engine with empty strings for the language and the country codes. Some logic in the tests and/or the framework appears to rely on that behavior. Whether that makes sense or not, I wouldn't venture to guess.
|
Looking at the test failures (pulled from the failing Travis job), my guess is that the test assumptions are wrong -- and that we should probably go with your initial fix, along with updating the test in It also doesn't explain why tests started failing inside Google only once #4450 was rolled into Google. |
|
Before the closure was set in #4450, |
|
On Android, With this PR, future platforms will be ensured to always get a I'm ok with this change if @Hixie is. |
|
ping @Hixie for thoughts -- see discussion above. |
|
I don't understand what this code is doing. Why is the engine reading window.locale? |
|
Ah, I see. This is an attempt to implement _localeName in platform_impl.dart? (Side note: looking at platform_impl.dart (the dart:io Platform implementation), I noticed a bug: |
|
The documentation for Platform.localeName doesn't say what the format will be so I don't really know what the correct fix is. |
|
I don't really understand why the existing implementations of |
|
Yes, |
|
Ah, my local copy must be behind. I would expect Platform.localeName to return the same as window.locale (but in whatever format we document Platform.localeName should return), so I agree with Todd that it seems weird to add a mention of en_US here. Also, we shouldn't parse the value (e.g. comparing to |
|
@zanderso Can you clarify your intent for this PR? Thanks. (I'm just cleaning out old PRs on the review queue.) |
|
Yeah, this is not the right fix. I'll close this. |
Another attempt to fix flutter/flutter#13748 that only modifies what is directly fed into
Platform.localeName.