diff options
author | Jason Wray <jason@mapbox.com> | 2018-01-09 16:09:41 -0500 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2018-01-10 17:26:11 -0500 |
commit | 0806e16eb390d9eb7db3157e23798f4010614aca (patch) | |
tree | e4e8a2d83ea49df8ec83b6d16e9f1c0b83a20140 /platform/ios/src/NSOrthography+MGLAdditions.m | |
parent | c9da6e495900cfe927d1f571e1687b20e0543dbd (diff) | |
download | qtlocation-mapboxgl-0806e16eb390d9eb7db3157e23798f4010614aca.tar.gz |
[ios] Fix and expand accessibility feature transliteration
- Fixed pre-iOS 11 compatibility.
- Expanded transliteration to all supported languages.
Diffstat (limited to 'platform/ios/src/NSOrthography+MGLAdditions.m')
-rw-r--r-- | platform/ios/src/NSOrthography+MGLAdditions.m | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/platform/ios/src/NSOrthography+MGLAdditions.m b/platform/ios/src/NSOrthography+MGLAdditions.m new file mode 100644 index 0000000000..99258862cc --- /dev/null +++ b/platform/ios/src/NSOrthography+MGLAdditions.m @@ -0,0 +1,31 @@ +#import "NSOrthography+MGLAdditions.h" + +@implementation NSOrthography (MGLAdditions) + ++ (NSString *)mgl_dominantScriptForMapboxStreetsLanguage:(NSString *)language { + if (@available(iOS 11.0, *)) { + NSLocale *locale = [NSLocale localeWithLocaleIdentifier:language]; + NSOrthography *orthography = [NSOrthography defaultOrthographyForLanguage:locale.localeIdentifier]; + + return orthography.dominantScript; + } + + // Manually map Mapbox Streets languages to ISO 15924 script codes. + NSSet *latinLanguages = [NSSet setWithObjects:@"de", @"en", @"es", @"fr", @"pt", nil]; + NSSet *hansLanguages = [NSSet setWithObjects:@"zh", @"zh-Hans", nil]; + + if ([latinLanguages containsObject:language]) { + return @"Latn"; + } else if ([hansLanguages containsObject:language]) { + return @"Hans"; + } else if ([language isEqualToString:@"ru"]) { + return @"Cyrl"; + } else if ([language isEqualToString:@"ar"]) { + return @"Arab"; + } else { + // Code for undetermined script + return @"Zyyy"; + } +} + +@end |