From b585ccf86c8017679ff152e41ff1327851b026a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 2 Nov 2017 17:54:51 -0700 Subject: [ios] Fixed feature name romanization in accessibility labels NSLocale.scriptCode is only set when the locale identifier explicitly specifies a script. Use NSOrthography to identify the dominant orthography regardless of locale. Also added a unit test of feature accessibility element labels. --- platform/ios/ios.xcodeproj/project.pbxproj | 8 ++++-- platform/ios/src/MGLMapAccessibilityElement.h | 8 +++++- platform/ios/src/MGLMapAccessibilityElement.mm | 12 +++++++-- .../ios/test/MGLMapAccessibilityElementTests.m | 31 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 platform/ios/test/MGLMapAccessibilityElementTests.m diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 29d02f6a6d..ad17e00673 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -292,6 +292,7 @@ DA35A2CB1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2C81CCAAAD200E826B2 /* NSValue+MGLAdditions.m */; }; DA35A2CC1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2C81CCAAAD200E826B2 /* NSValue+MGLAdditions.m */; }; DA35D0881E1A6309007DED41 /* one-liner.json in Resources */ = {isa = PBXBuildFile; fileRef = DA35D0871E1A6309007DED41 /* one-liner.json */; }; + DA5DB12A1FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5DB1291FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m */; }; DA6408DB1DA4E7D300908C90 /* MGLVectorStyleLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = DA6408D91DA4E7D300908C90 /* MGLVectorStyleLayer.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA6408DC1DA4E7D300908C90 /* MGLVectorStyleLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = DA6408D91DA4E7D300908C90 /* MGLVectorStyleLayer.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA6408DD1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = DA6408DA1DA4E7D300908C90 /* MGLVectorStyleLayer.m */; }; @@ -806,6 +807,7 @@ DA57D4AC1EBA922A00793288 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = vi; path = vi.lproj/Localizable.stringsdict; sourceTree = ""; }; DA5C09BA1EFC48550056B178 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Localizable.strings; sourceTree = ""; }; DA5C09BB1EFC486C0056B178 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Localizable.strings; sourceTree = ""; }; + DA5DB1291FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapAccessibilityElementTests.m; sourceTree = ""; }; DA6023F11E4CE94300DBFF23 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Foundation.strings; sourceTree = ""; }; DA6023F21E4CE94800DBFF23 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = sv; path = sv.lproj/Foundation.stringsdict; sourceTree = ""; }; DA618B111E68823600CB7F44 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ru; path = ru.lproj/Localizable.stringsdict; sourceTree = ""; }; @@ -1354,6 +1356,7 @@ 3598544C1E1D38AA00B29F84 /* MGLDistanceFormatterTests.m */, DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */, DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */, + DA5DB1291FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m */, 35E208A61D24210F00EC9A46 /* MGLNSDataAdditionsTests.m */, 1F95931C1E6DE2E900D5B294 /* MGLNSDateAdditionsTests.mm */, DAE7DEC11E245455007505A6 /* MGLNSStringAdditionsTests.m */, @@ -2286,6 +2289,7 @@ DA2E88621CC0382C00F24E7B /* MGLOfflinePackTests.m in Sources */, 55E2AD131E5B125400E8C587 /* MGLOfflineStorageTests.mm in Sources */, 920A3E5D1E6F995200C16EFC /* MGLSourceQueryTests.m in Sources */, + DA5DB12A1FABF1EE001C2326 /* MGLMapAccessibilityElementTests.m in Sources */, FAE1CDCB1E9D79CB00C40B5B /* MGLFillExtrusionStyleLayerTests.mm in Sources */, DA35A2AA1CCA058D00E826B2 /* MGLCoordinateFormatterTests.m in Sources */, 357579831D502AE6000B822E /* MGLRasterStyleLayerTests.mm in Sources */, @@ -2771,7 +2775,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2785,7 +2789,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/platform/ios/src/MGLMapAccessibilityElement.h b/platform/ios/src/MGLMapAccessibilityElement.h index efe077fac9..952f6cbf2f 100644 --- a/platform/ios/src/MGLMapAccessibilityElement.h +++ b/platform/ios/src/MGLMapAccessibilityElement.h @@ -1,5 +1,7 @@ #import +#import "MGLFoundation.h" + NS_ASSUME_NONNULL_BEGIN @protocol MGLFeature; @@ -8,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN typedef uint32_t MGLAnnotationTag; /** An accessibility element representing something that appears on the map. */ +MGL_EXPORT @interface MGLMapAccessibilityElement : UIAccessibilityElement @end @@ -23,6 +26,7 @@ typedef uint32_t MGLAnnotationTag; @end /** An accessibility element representing a map feature. */ +MGL_EXPORT @interface MGLFeatureAccessibilityElement : MGLMapAccessibilityElement /** The feature represented by this element. */ @@ -33,16 +37,18 @@ typedef uint32_t MGLAnnotationTag; @end /** An accessibility element representing a place feature. */ +MGL_EXPORT @interface MGLPlaceFeatureAccessibilityElement : MGLFeatureAccessibilityElement @end /** An accessibility element representing a road feature. */ +MGL_EXPORT @interface MGLRoadFeatureAccessibilityElement : MGLFeatureAccessibilityElement @end /** An accessibility element representing the MGLMapView at large. */ +MGL_EXPORT @interface MGLMapViewProxyAccessibilityElement : UIAccessibilityElement - @end NS_ASSUME_NONNULL_END diff --git a/platform/ios/src/MGLMapAccessibilityElement.mm b/platform/ios/src/MGLMapAccessibilityElement.mm index 2baf4aea7c..e36f35a60b 100644 --- a/platform/ios/src/MGLMapAccessibilityElement.mm +++ b/platform/ios/src/MGLMapAccessibilityElement.mm @@ -53,8 +53,16 @@ // may be in the local language, which may be written in another script. // Romanize it. NSLocale *locale = [NSLocale localeWithLocaleIdentifier:languageCode]; - NSString *scriptCode = [locale objectForKey:NSLocaleScriptCode]; - if ([scriptCode isEqualToString:@"Latn"]) { + 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]; } diff --git a/platform/ios/test/MGLMapAccessibilityElementTests.m b/platform/ios/test/MGLMapAccessibilityElementTests.m new file mode 100644 index 0000000000..67bbb08710 --- /dev/null +++ b/platform/ios/test/MGLMapAccessibilityElementTests.m @@ -0,0 +1,31 @@ +#import +#import + +#import "../../ios/src/MGLMapAccessibilityElement.h" + +@interface MGLMapAccessibilityElementTests : XCTestCase +@end + +@implementation MGLMapAccessibilityElementTests + +- (void)testFeatureLabels { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + feature.attributes = @{ + @"name": @"Local", + @"name_en": @"English", + @"name_es": @"Spanish", + @"name_fr": @"French", + @"name_tlh": @"Klingon", + }; + MGLFeatureAccessibilityElement *element = [[MGLFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:feature]; + XCTAssertEqualObjects(element.accessibilityLabel, @"English", @"Accessibility label should be localized."); + + feature.attributes = @{ + @"name": @"Цинциннати", + @"name_en": @"Цинциннати", + }; + element = [[MGLFeatureAccessibilityElement alloc] initWithAccessibilityContainer:self feature:feature]; + XCTAssertEqualObjects(element.accessibilityLabel, @"Cincinnati", @"Accessibility label should be romanized."); +} + +@end -- cgit v1.2.1