Unverified Commit 0e735e4b authored by Gary Qian's avatar Gary Qian Committed by GitHub

Expose ComputePlatformResolvedLocale (#58482)

parent e8670de0
......@@ -944,6 +944,46 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
buildOwner.reassemble(renderViewElement);
return super.performReassemble();
}
/// Computes the locale the current platform would resolve to.
///
/// This method is meant to be used as part of a [localeListResolutionCallback].
/// Since this method may return null, a Flutter/dart algorithm should still be
/// provided as a fallback in case a native resolved locale cannot be determined
/// or if the native resolved locale is undesirable.
///
/// This method may return a null [Locale] if the platform does not support
/// native locale resolution, or if the resolution failed.
///
/// The first [supportedLocale] is treated as the default locale and will be returned
/// if no better match is found.
///
/// Android and iOS are currently supported.
///
/// On Android, the algorithm described in
/// https://developer.android.com/guide/topics/resources/multilingual-support
/// is used to determine the resolved locale. Depending on the android version
/// of the device, either the modern (>= API 24) or legacy (< API 24) algorithm
/// will be used.
///
/// On iOS, the result of `preferredLocalizationsFromArray` method of `NSBundle`
/// is returned. See:
/// https://developer.apple.com/documentation/foundation/nsbundle/1417249-preferredlocalizationsfromarray?language=objc
/// for details on the used method.
///
/// iOS treats script code as necessary for a match, so a user preferred locale of
/// `zh_Hans_CN` will not resolve to a supported locale of `zh_CN`.
///
/// Since implementation may vary by platform and has potential to be heavy,
/// it is recommended to cache the results of this method if the value is
/// used multiple times.
///
/// Second-best (and n-best) matching locales should be obtained by calling this
/// method again with the matched locale of the first call omitted from
/// [supportedLocales].
Locale computePlatformResolvedLocale(List<Locale> supportedLocales) {
return window.computePlatformResolvedLocale(supportedLocales);
}
}
/// Inflate the given widget and attach it to the screen.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment