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

Commit 56a59ae

Browse files
committed
Select best language based on locale setting and our support
1 parent e9b265b commit 56a59ae

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

platform/ios/app/MBXViewController.m

+20-1
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,31 @@ - (void)styleDynamicPointCollection
914914

915915
- (void)styleCountryLabelLanguage
916916
{
917+
NSString *bestLanguageForUser = [NSString stringWithFormat:@"{name_%@}", [self bestLanguageForUser]];
917918
MGLSymbolStyleLayer *countryLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"country-label-lg"];
918919
MGLStyleConstantValue<NSString *> *countryLabel = (MGLStyleConstantValue<NSString *> *)countryLayer.textField;
919-
NSString *language = [countryLabel.rawValue isEqual:@"{name_zh}"] ? @"{name_en}" : @"{name_zh}";
920+
NSString *language = [countryLabel.rawValue isEqual:bestLanguageForUser] ? @"{name}" : bestLanguageForUser;
920921
countryLayer.textField = [MGLStyleValue<NSString *> valueWithRawValue:language];
921922
}
922923

924+
- (NSString *)bestLanguageForUser
925+
{
926+
NSArray *supportedLanguages = @[ @"en", @"es", @"fr", @"de", @"ru", @"zh" ];
927+
NSArray<NSString *> *preferredLanguages = [NSLocale preferredLanguages];
928+
NSString *bestLanguage;
929+
930+
for (NSString *language in preferredLanguages) {
931+
NSString *thisLanguage = [language substringToIndex:2];
932+
if ([supportedLanguages containsObject:thisLanguage])
933+
{
934+
bestLanguage = thisLanguage;
935+
break;
936+
}
937+
}
938+
939+
return bestLanguage ?: @"en";
940+
}
941+
923942
- (IBAction)startWorldTour
924943
{
925944
_isTouringWorld = YES;

0 commit comments

Comments
 (0)