From 6a1ad20ce9eac21a4ab3a2b7a14521821e316d05 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Mon, 7 Mar 2016 14:37:10 -0800 Subject: [PATCH] Wire up locale notifications to ios. Fixes #2282 --- sky/shell/platform/ios/sky_surface.mm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sky/shell/platform/ios/sky_surface.mm b/sky/shell/platform/ios/sky_surface.mm index 811652c3b4..842a701370 100644 --- a/sky/shell/platform/ios/sky_surface.mm +++ b/sky/shell/platform/ios/sky_surface.mm @@ -157,6 +157,12 @@ static std::string TracesBasePath() { selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; + + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(onLocaleUpdated:) + name:NSCurrentLocaleDidChangeNotification + object:nil]; } return self; } @@ -179,6 +185,13 @@ static std::string TracesBasePath() { _engine->OnViewportMetricsChanged(_viewportMetrics.Clone()); } +- (void)onLocaleUpdated:(NSNotification*)notification { + NSLocale *currentLocale = [NSLocale currentLocale]; + NSString *languageCode = [currentLocale objectForKey:NSLocaleLanguageCode]; + NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; + _engine->OnLocaleChanged(languageCode.UTF8String, countryCode.UTF8String); +} + - (void)layoutSubviews { TRACE_EVENT0("flutter", "layoutSubviews"); [super layoutSubviews]; @@ -253,6 +266,9 @@ static std::string TracesBasePath() { services->services_provided_by_embedder = service_provider.Pass(); _engine->SetServices(services.Pass()); + // Initialize to current locale + [self onLocaleUpdated:nil]; + #if TARGET_IPHONE_SIMULATOR [self runFromDartSource]; #else -- GitLab