diff --git a/lib/ui/hooks.dart b/lib/ui/hooks.dart index 65c5529f156d845f075c556efea315cca6be7056..20980a0a1c41f14d7a3970eb507a114b1f9487bd 100644 --- a/lib/ui/hooks.dart +++ b/lib/ui/hooks.dart @@ -48,7 +48,7 @@ String _localeClosure() => window._locale.toString(); _LocaleClosure _getLocaleClosure() => _localeClosure; @pragma('vm:entry-point') -void _updateLocale(String languageCode, String countryCode) { +void _updateLocale(String languageCode, String countryCode, String scriptCode, String variantCode) { window._locale = new Locale(languageCode, countryCode); _invoke(window.onLocaleChanged, window._onLocaleChangedZone); } diff --git a/lib/ui/window/window.cc b/lib/ui/window/window.cc index 783b025b7189acb3d94e1069c3edd332bcdaecfb..95be0076198ccf9d37f5632c7afca7b272bf0eb3 100644 --- a/lib/ui/window/window.cc +++ b/lib/ui/window/window.cc @@ -163,7 +163,9 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) { } void Window::UpdateLocale(const std::string& language_code, - const std::string& country_code) { + const std::string& country_code, + const std::string& script_code, + const std::string& variant_code) { std::shared_ptr dart_state = library_.dart_state().lock(); if (!dart_state) return; @@ -173,6 +175,8 @@ void Window::UpdateLocale(const std::string& language_code, { StdStringToDart(language_code), StdStringToDart(country_code), + StdStringToDart(script_code), + StdStringToDart(variant_code), }); } diff --git a/lib/ui/window/window.h b/lib/ui/window/window.h index 44f348d07fc3efaa852ca498409cdc54ec85e45c..eb2a8c6613d0702d9711d3fd579119a631ff1277 100644 --- a/lib/ui/window/window.h +++ b/lib/ui/window/window.h @@ -60,7 +60,9 @@ class Window final { void DidCreateIsolate(); void UpdateWindowMetrics(const ViewportMetrics& metrics); void UpdateLocale(const std::string& language_code, - const std::string& country_code); + const std::string& country_code, + const std::string& script_code, + const std::string& variant_code); void UpdateUserSettingsData(const std::string& data); void UpdateSemanticsEnabled(bool enabled); void UpdateAccessibilityFeatures(int32_t flags); diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index d3509ed080b40f54c088fdcb90da3968cca7a379..7e0bd024c66cc9b0dd0fae652b106e8ba17abb4c 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -124,7 +124,8 @@ std::unique_ptr RuntimeController::Clone() const { bool RuntimeController::FlushRuntimeStateToIsolate() { return SetViewportMetrics(window_data_.viewport_metrics) && - SetLocale(window_data_.language_code, window_data_.country_code) && + SetLocale(window_data_.language_code, window_data_.country_code, + window_data_.script_code, window_data_.variant_code) && SetSemanticsEnabled(window_data_.semantics_enabled) && SetAccessibilityFeatures(window_data_.accessibility_feature_flags_); } @@ -140,12 +141,17 @@ bool RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) { } bool RuntimeController::SetLocale(const std::string& language_code, - const std::string& country_code) { + const std::string& country_code, + const std::string& script_code, + const std::string& variant_code) { window_data_.language_code = language_code; window_data_.country_code = country_code; + window_data_.script_code = script_code; + window_data_.variant_code = variant_code; if (auto window = GetWindowIfAvailable()) { - window->UpdateLocale(window_data_.language_code, window_data_.country_code); + window->UpdateLocale(window_data_.language_code, window_data_.country_code, + window_data_.script_code, window_data_.variant_code); return true; } diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index c2a909f6edceb751f1602c55c42869caca692c38..67c7f3e44cb83a918c27c0a530868a2f6b177689 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -41,7 +41,9 @@ class RuntimeController final : public WindowClient { bool SetViewportMetrics(const ViewportMetrics& metrics); bool SetLocale(const std::string& language_code, - const std::string& country_code); + const std::string& country_code, + const std::string& script_code, + const std::string& variant_code); bool SetUserSettingsData(const std::string& data); @@ -80,6 +82,8 @@ class RuntimeController final : public WindowClient { ViewportMetrics viewport_metrics; std::string language_code; std::string country_code; + std::string script_code; + std::string variant_code; std::string user_settings_data = "{}"; bool semantics_enabled = false; bool assistive_technology_enabled = false; diff --git a/shell/common/engine.cc b/shell/common/engine.cc index f8ba2ad3b07771e16fd8bcad3d58fabec3db39f0..5e1f53a55912d1376b38ff4ef3baf193c0e6f377 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -327,12 +327,15 @@ bool Engine::HandleLocalizationPlatformMessage( const auto& language = args->value[0]; const auto& country = args->value[1]; + const auto& script = args->value[2]; + const auto& variant = args->value[3]; if (!language.IsString() || !country.IsString()) return false; return runtime_controller_->SetLocale(language.GetString(), - country.GetString()); + country.GetString(), script.GetString(), + variant.GetString()); } void Engine::HandleSettingsPlatformMessage(blink::PlatformMessage* message) { diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index fe7002c3be2659f0dd33406572242286669d1162..8778877486875c47cd0e3fd0885defe64165842a 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -317,7 +317,7 @@ public class FlutterView extends SurfaceView } private void setLocale(Locale locale) { - mFlutterLocalizationChannel.invokeMethod("setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry())); + mFlutterLocalizationChannel.invokeMethod("setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry(), locale.getScript(), locale.getVariant())); } @Override diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index d9da2160d9cc915e12001faed42e1c604f2cb154..471e88e2dc5ca6ee2f1c0322720c542792fbe24e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -894,8 +894,16 @@ static blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) { NSLocale* currentLocale = [NSLocale currentLocale]; NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode]; NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; + NSString* scriptCode = [currentLocale objectForKey:NSLocaleScriptCode]; + NSString* variantCode = [currentLocale objectForKey:NSLocaleVariantCode]; if (languageCode && countryCode) - [_localizationChannel.get() invokeMethod:@"setLocale" arguments:@[ languageCode, countryCode ]]; + // We pass empty strings for undefined scripts and variants to ensure the JSON encoder/decoder + // functions properly. + [_localizationChannel.get() invokeMethod:@"setLocale" + arguments:@[ + languageCode, countryCode, scriptCode ? scriptCode : @"", + variantCode ? variantCode : @"" + ]]; } #pragma mark - Set user settings diff --git a/testing/dart/window_hooks_integration_test.dart b/testing/dart/window_hooks_integration_test.dart index ee4d6d6e16a84edeacc4fe649c86a1fb05a9b1dc..b56aaeee4d1e9a404d20a5eec283d0a3c2aaee57 100644 --- a/testing/dart/window_hooks_integration_test.dart +++ b/testing/dart/window_hooks_integration_test.dart @@ -100,7 +100,7 @@ void main() { }; }); - _updateLocale('en', 'US'); + _updateLocale('en', 'US', '', ''); expect(runZone, isNotNull); expect(runZone, same(innerZone)); expect(locale, equals(const Locale('en', 'US')));