@@ -41,6 +41,13 @@ static void UpdateNativeThreadLabelNames(const std::string& label,
4141 set_thread_name (runners.GetIOTaskRunner (), label, " .io" );
4242}
4343
44+ static fml::RefPtr<flutter::PlatformMessage> MakeLocalizationPlatformMessage (
45+ const fuchsia::intl::Profile& intl_profile) {
46+ return fml::MakeRefCounted<flutter::PlatformMessage>(
47+ " flutter/localization" , MakeLocalizationPlatformMessageData (intl_profile),
48+ nullptr );
49+ }
50+
4451Engine::Engine (Delegate& delegate,
4552 std::string thread_label,
4653 std::shared_ptr<sys::ServiceDirectory> svc,
@@ -256,6 +263,54 @@ Engine::Engine(Delegate& delegate,
256263 // notification. Fire one eagerly.
257264 shell_->GetPlatformView ()->NotifyCreated ();
258265
266+ // Connect to the intl property provider. If the connection fails, the
267+ // initialization of the engine will simply proceed, printing a warning
268+ // message. The engine will be fully functional, except that the user's
269+ // locale preferences would not be communicated to flutter engine.
270+ {
271+ intl_property_provider_.set_error_handler ([](zx_status_t status) {
272+ FML_LOG (WARNING) << " Failed to connect to "
273+ << fuchsia::intl::PropertyProvider::Name_ << " : "
274+ << zx_status_get_string (status)
275+ << " This is not a fatal error, but the user locale "
276+ << " preferences will not be forwarded to flutter apps" ;
277+ });
278+
279+ // Note that we're using the runner's services, not the component's.
280+ // Flutter locales should be updated regardless of whether the component has
281+ // direct access to the fuchsia.intl.PropertyProvider service.
282+ ZX_ASSERT (runner_services->Connect (intl_property_provider_.NewRequest ()) ==
283+ ZX_OK);
284+
285+ auto get_profile_callback = [flutter_runner_engine =
286+ weak_factory_.GetWeakPtr ()](
287+ const fuchsia::intl::Profile& profile) {
288+ if (!flutter_runner_engine) {
289+ return ;
290+ }
291+ if (!profile.has_locales ()) {
292+ FML_LOG (WARNING) << " Got intl Profile without locales" ;
293+ }
294+ auto message = MakeLocalizationPlatformMessage (profile);
295+ FML_VLOG (-1 ) << " Sending LocalizationPlatformMessage" ;
296+ flutter_runner_engine->shell_ ->GetPlatformView ()->DispatchPlatformMessage (
297+ message);
298+ };
299+
300+ FML_VLOG (-1 ) << " Requesting intl Profile" ;
301+
302+ // Make the initial request
303+ intl_property_provider_->GetProfile (get_profile_callback);
304+
305+ // And register for changes
306+ intl_property_provider_.events ().OnChange = [this , runner_services,
307+ get_profile_callback]() {
308+ FML_VLOG (-1 ) << fuchsia::intl::PropertyProvider::Name_ << " : OnChange" ;
309+ runner_services->Connect (intl_property_provider_.NewRequest ());
310+ intl_property_provider_->GetProfile (get_profile_callback);
311+ };
312+ }
313+
259314 // Launch the engine in the appropriate configuration.
260315 auto run_configuration = flutter::RunConfiguration::InferFromSettings (
261316 settings_, task_runners.GetIOTaskRunner ());
0 commit comments