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

Conversation

@GaryQian
Copy link
Contributor

To properly support locale resolution, we now pass the full set of locales defined on the user's device instead of just the first one.

Full integration is pending #6481. Currently, the script and variant codes are not passed into the Locale object yet, which will be done once Locale supports it.

@GaryQian
Copy link
Contributor Author

Will update with working Android-side code.

Copy link

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

Just looked over the dart changes, which seem fine. Just a few suggestions to prove that I read the code :-).

/// This establishes the language and formatting conventions that application
/// should, if possible, use to render their user interface.
///
/// This is the first locale selected by the user and should be the user's

Choose a reason for hiding this comment

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

Nit: "should be the user's primary locale" begs some questions:

  • What's the primary locale exactly?
  • When would it not be the primary locale?

Including a link to a public document that covered this kind of thing would be helpful.

/// This is the first locale selected by the user and should be the user's
/// primary locale.
///
/// This is equivalent to `locales[0]` and will provide an empty non-null locale

Choose a reason for hiding this comment

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

locales.first

if (_locales != null && _locales.length != 0) {
return _locales[0];
}
return new Locale("", "");

Choose a reason for hiding this comment

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

It might be better to define a Locale.none constant and use that here.

/// This is equivalent to `locales[0]` and will provide an empty non-null locale
/// if the [locales] list has not been set or is empty.
Locale get locale {
if (_locales != null && _locales.length != 0) {

Choose a reason for hiding this comment

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

_locales.isNotEmpty

/// should, if possible, use to render their user interface.
///
/// The list is ordered in order of priority, with lower-indexed locales being
/// preferred over higher-indexed ones. The zeroth element is the default [locale].

Choose a reason for hiding this comment

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

zeroth - first

Earlier, locales[0] was referred to as the "primary" locale.

/// if the [locales] list has not been set or is empty.
Locale get locale {
if (_locales != null && _locales.length != 0) {
return _locales[0];

Choose a reason for hiding this comment

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

_locales.first

@GaryQian
Copy link
Contributor Author

This is part of the fix for flutter/flutter#22642

@GaryQian GaryQian merged commit 35340ce into flutter:master Oct 17, 2018
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 17, 2018
flutter/engine@04c860f...8cc49ca

git log 04c860f..8cc49ca --no-merges --oneline
8cc49ca Ensure that the isolate shutdown callback occurs in an isolate scope. (flutter/engine#6572)
04a1ffa Roll src/third_party/skia cb65ce7f77c9..3a0c66da5fc2 (10 commits) (flutter/engine#6571)
35340ce Pass full locale list with script and variant codes to framework (flutter/engine#6557)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
liyuqian added a commit to liyuqian/flutter that referenced this pull request Oct 17, 2018
And update goldens.

git log 04c860f..8cc49ca --no-merges --oneline
8cc49ca Ensure that the isolate shutdown callback occurs in an isolate scope. (flutter/engine#6572)
04a1ffa Roll src/third_party/skia cb65ce7f77c9..3a0c66da5fc2 (10 commits) (flutter/engine#6571)
35340ce Pass full locale list with script and variant codes to framework (flutter/engine#6557)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 18, 2018
flutter/engine@04c860f...705738f

git log 04c860f..705738f --no-merges --oneline
705738f Roll src/third_party/skia 3a0c66da5fc2..928db927f7fc (5 commits) (flutter/engine#6573)
8cc49ca Ensure that the isolate shutdown callback occurs in an isolate scope. (flutter/engine#6572)
04a1ffa Roll src/third_party/skia cb65ce7f77c9..3a0c66da5fc2 (10 commits) (flutter/engine#6571)
35340ce Pass full locale list with script and variant codes to framework (flutter/engine#6557)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 18, 2018
flutter/engine@04c860f...979de07

git log 04c860f..979de07 --no-merges --oneline
979de07 Add a CountDownLatch to fml with tests. (flutter/engine#6574)
705738f Roll src/third_party/skia 3a0c66da5fc2..928db927f7fc (5 commits) (flutter/engine#6573)
8cc49ca Ensure that the isolate shutdown callback occurs in an isolate scope. (flutter/engine#6572)
04a1ffa Roll src/third_party/skia cb65ce7f77c9..3a0c66da5fc2 (10 commits) (flutter/engine#6571)
35340ce Pass full locale list with script and variant codes to framework (flutter/engine#6557)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 18, 2018
flutter/engine@04c860f...607c05c

git log 04c860f..607c05c --no-merges --oneline
607c05c Run all supported host unit tests on Cirrus. (flutter/engine#6575)
979de07 Add a CountDownLatch to fml with tests. (flutter/engine#6574)
705738f Roll src/third_party/skia 3a0c66da5fc2..928db927f7fc (5 commits) (flutter/engine#6573)
8cc49ca Ensure that the isolate shutdown callback occurs in an isolate scope. (flutter/engine#6572)
04a1ffa Roll src/third_party/skia cb65ce7f77c9..3a0c66da5fc2 (10 commits) (flutter/engine#6571)
35340ce Pass full locale list with script and variant codes to framework (flutter/engine#6557)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
liyuqian added a commit to flutter/flutter that referenced this pull request Oct 18, 2018
And update goldens.

git log 04c860f..8cc49ca --no-merges --oneline
8cc49ca Ensure that the isolate shutdown callback occurs in an isolate scope. (flutter/engine#6572)
04a1ffa Roll src/third_party/skia cb65ce7f77c9..3a0c66da5fc2 (10 commits) (flutter/engine#6571)
35340ce Pass full locale list with script and variant codes to framework (flutter/engine#6557)
const Locale(this._languageCode, [ this._countryCode ]) : assert(_languageCode != null);

/// Empty locale constant. This is an invalid locale.
static const Locale none = const Locale('', '');
Copy link
Contributor

Choose a reason for hiding this comment

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

why not null?

Copy link
Contributor

Choose a reason for hiding this comment

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

or just assert that it's never empty -- can we ever have no locale at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There seems to be a large string of calls that do not expect the returned locale to ever be null. I can look into changing it to do null checking though, since that is probably a more robust design in the long run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This mostly applies to when the locale is accessed before the platform has had a chance to pass it over on startup. The empty locale would just result in the resolution to use the default (first) locale.

@miDeb
Copy link

miDeb commented Oct 18, 2018

It seems as setLocales(https://github.com/GaryQian/engine/blob/982dc4f3f3fbd69ccaed1862e6cc20ab6cf21e39/shell/platform/android/io/flutter/view/FlutterView.java#L348) lets my app crash:

java.lang.NoSuchMethodError: java.util.Locale.getScript
        at io.flutter.view.FlutterView.setLocales(FlutterView.java:348)
        at io.flutter.view.FlutterView.<init>(FlutterView.java:175)
        at io.flutter.app.FlutterActivityDelegate.onCreate(FlutterActivityDelegate.java:157)
        at io.flutter.app.FlutterActivity.onCreate(FlutterActivity.java:85)
        at com.example.flutterlpcc.MainActivity.onCreate(MainActivity.java:10)
        at android.app.Activity.performCreate(Activity.java:5442)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
        at android.app.ActivityThread.access$800(ActivityThread.java:166)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5584)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
        at dalvik.system.NativeStart.main(Native Method)

My device is API 19 and Locale.getScript was introduced in API 21, so it will probably be because of this.

@GaryQian
Copy link
Contributor Author

Ahh good catch, my bad, I'll fix that asap.

@tvolkert
Copy link
Contributor

This looks like it might have triggered flutter/flutter#23241 (see original fix in #4495)

/cc @yjbanov @zanderso

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants