Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Select best language based on locale setting and our support
Browse files Browse the repository at this point in the history
  • Loading branch information
friedbunny committed Oct 26, 2016
1 parent 68be7cd commit 89bc8ef
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *> *countryLabel = (MGLStyleConstantValue<NSString *> *)countryLayer.textField;
NSString *language = [countryLabel.rawValue isEqual:@"{name_zh}"] ? @"{name_en}" : @"{name_zh}";
NSString *language = [countryLabel.rawValue isEqual:bestLanguageForUser] ? @"{name}" : bestLanguageForUser;
countryLayer.textField = [MGLStyleValue<NSString *> valueWithRawValue:language];
}

- (NSString *)bestLanguageForUser
{
NSArray *supportedLanguages = @[ @"en", @"es", @"fr", @"de", @"ru", @"zh" ];
NSArray<NSString *> *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;
Expand Down

0 comments on commit 89bc8ef

Please sign in to comment.