From 89bc8efc1564f61a7741e2c55383c1ca4d5ac1c9 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 25 Oct 2016 18:20:19 -0700 Subject: [PATCH] Select best language based on locale setting and our support --- platform/ios/app/MBXViewController.m | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 5b4385479c8..40be7dc8fec 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -914,12 +914,31 @@ - (void)styleDynamicPointCollection - (void)styleCountryLabelLanguage { + NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]]; MGLSymbolStyleLayer *countryLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"country-label-lg"]; MGLStyleConstantValue *countryLabel = (MGLStyleConstantValue *)countryLayer.textField; - NSString *language = [countryLabel.rawValue isEqual:@"{name_zh}"] ? @"{name_en}" : @"{name_zh}"; + NSString *language = [countryLabel.rawValue isEqual:bestLanguageForUser] ? @"{name}" : bestLanguageForUser; countryLayer.textField = [MGLStyleValue valueWithRawValue:language]; } +- (NSString *)bestLanguageForUser +{ + NSArray *supportedLanguages = @[ @"en", @"es", @"fr", @"de", @"ru", @"zh" ]; + NSArray *preferredLanguages = [NSLocale preferredLanguages]; + NSString *bestLanguage; + + for (NSString *language in preferredLanguages) { + NSString *thisLanguage = [language substringToIndex:2]; + if ([supportedLanguages containsObject:thisLanguage]) + { + bestLanguage = thisLanguage; + break; + } + } + + return bestLanguage ?: @"en"; +} + - (IBAction)startWorldTour { _isTouringWorld = YES;