diff options
Diffstat (limited to 'platform/ios/src/MGLMapAccessibilityElement.mm')
-rw-r--r-- | platform/ios/src/MGLMapAccessibilityElement.mm | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/platform/ios/src/MGLMapAccessibilityElement.mm b/platform/ios/src/MGLMapAccessibilityElement.mm index 1a2953b0bb..79dcda4054 100644 --- a/platform/ios/src/MGLMapAccessibilityElement.mm +++ b/platform/ios/src/MGLMapAccessibilityElement.mm @@ -7,6 +7,8 @@ #import "MGLVectorSource_Private.h" #import "NSBundle+MGLAdditions.h" +#import "NSOrthography+MGLAdditions.h" +#import "NSString+MGLAdditions.h" @implementation MGLMapAccessibilityElement @@ -49,24 +51,16 @@ NSString *languageCode = [MGLVectorSource preferredMapboxStreetsLanguage]; NSString *nameAttribute = [NSString stringWithFormat:@"name_%@", languageCode]; NSString *name = [feature attributeForKey:nameAttribute]; - + // If a feature hasn’t been translated into the preferred language, it // may be in the local language, which may be written in another script. - // Romanize it. - NSLocale *locale = [NSLocale localeWithLocaleIdentifier:languageCode]; - NSOrthography *orthography; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunguarded-availability-new" - if ([NSOrthography respondsToSelector:@selector(defaultOrthographyForLanguage:)]) { - orthography = [NSOrthography defaultOrthographyForLanguage:locale.localeIdentifier]; - } -#pragma clang diagnostic pop -#endif - if ([orthography.dominantScript isEqualToString:@"Latn"]) { - name = [name stringByApplyingTransform:NSStringTransformToLatin reverse:NO]; + // Attempt to transform to the script of the preferred language, keeping + // the original string if no transform exists or if transformation fails. + if (@available(iOS 9.0, *)) { + NSString *dominantScript = [NSOrthography mgl_dominantScriptForMapboxStreetsLanguage:languageCode]; + name = [name mgl_stringByTransliteratingIntoScript:dominantScript]; } - + self.accessibilityLabel = name; } return self; |