Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Implement local, locales, and onLocaleChanged for the web - #18137

Merged
yjbanov merged 4 commits into
flutter-team-archive:masterfrom
yjbanov:locales
May 16, 2020
Merged

yjbanov merged 4 commits into
flutter-team-archive:masterfrom
yjbanov:locales

Conversation

@yjbanov

@yjbanov yjbanov commented May 5, 2020 •

Copy link
Copy Markdown
Contributor

Fixes flutter/flutter#54669
Fixes flutter/flutter#48886

Here's the new gallery after I changed my Chrome default language to Russian:

gallery-in-russian

@yjbanov
yjbanov requested a review from slightfoot May 5, 2020 00:38
@googlebot

Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot

Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@yjbanov

yjbanov commented May 5, 2020

Copy link
Copy Markdown
Contributor Author

@slightfoot Can you please OK including your commits in this PR? #18137 (comment) has the details.

@slightfoot

Copy link
Copy Markdown
Contributor

Yes. Your welcome to my commits.

@yjbanov

yjbanov commented May 5, 2020

Copy link
Copy Markdown
Contributor Author

Yes. Your welcome to my commits.

Thanks! Looks like the googlebot wants you to follow this small instruction: We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

@slightfoot

Copy link
Copy Markdown
Contributor

@googlebot I consent

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

1 similar comment
@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels May 5, 2020

@mdebbar mdebbar 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.

LGTM

Comment thread lib/web_ui/lib/src/engine/window.dart Outdated
_onLocaleChangedZone = Zone.current;
}

/// The locale used when we fails to get the list from the browser.

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.

typo: "we fail"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread lib/web_ui/lib/src/engine/window.dart Outdated
Comment on lines +220 to +224
// To make it easier for the app code, let's not leave the locales list
// empty. This way there's fewer corner cases for apps to handle.
if (locales.isEmpty) {
locales.add(_defaultLocale);
}

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.

Suggestion: return early before the for loop.

if (!js_util.hasProperty(html.window.navigator, 'languages')) {
  return const [_defaultLocale];
}

if (html.window.navigator.languages.isEmpty) {
  return const [_defaultLocale];
}

for (final String language in html.window.navigator.languages) {
  // ...
}
return locales;

This is just a personal preference of mine. It makes reading the code easier when edge cases are handled at the beginning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. I actually prefer that too, but missed it this time.

@slightfoot slightfoot 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.

I have not run the code changes yet. It looks good, however there's quite a few formatting based line changes in the change set. I'll see if I can find some time today or tomorrow to test it out.

@yjbanov
yjbanov merged commit 570b474 into flutter-team-archive:master May 16, 2020
@yjbanov

yjbanov commented May 16, 2020

Copy link
Copy Markdown
Contributor Author

@slightfoot LMK whether this is working for you. I tested by changing the browser language to "ru" and running the new Flutter Gallery (see screenshot in the PR description).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

Flutter for web : Can we use Internationalization? [web] locale / onLocaleChanged not implemented

4 participants