Hindi, Thai and Japanese person name parsing (PersonNameComponentsFormatter) does not work as expected
Originator: | tmharada | ||
Number: | rdar://44370991 | Date Originated: | 2018-09-11 |
Status: | Open | Resolved: | |
Product: | Foundation | Product Version: | |
Classification: | Reproducible: | Always |
Area: Foundation Summary: PersonNameComponentsFormatter's personNameComponents method works great for Chinese, English, Spanish and some other languages. However, it doesn't work so well for French, Thai, Japanese and Hindi. E.g., I would expect feeding in the default names from: https://developer.apple.com/documentation/foundation/personnamecomponentsformatter and outputting an abbreviated name would result in the initials mentioned in that document. Steps to Reproduce: In the following cases where the comparison is to the "" (empty string), I'd expect there to actually be a valid set of initials returned. // English: Prefix, First Name, Middle Name, Last Name, Suffix XCTAssertEqual("Mr John Binksy Smith III".personNameInitials, "JS") // Arabic XCTAssertEqual("أحمد محمﺩﺍلمصﺭﻱ".personNameInitials, "") // Chinese XCTAssertEqual("杨振宁".personNameInitials, "杨") // Spanish: super long name XCTAssertEqual("Dr. José Ramiro Martín González de Rivera júnior, PhD".personNameInitials, "JM") // Hindi: no abbreviation determinated XCTAssertEqual("डॉ. रिय साहिल".personNameInitials, "") // Thai XCTAssertEqual("สมชาย รัตนเรืองรอง บวรทิพย์".personNameInitials, "") // Japanese XCTAssertEqual("木田".personNameInitials, "木田") // French XCTAssertEqual("Jean-Philippe de Zélicourt".personNameInitials, "JD") Implementation of personNameInitials: var personNameInitials: String { let formatter = PersonNameComponentsFormatter() var nameInitials = [Character]() guard let personNameComponents = formatter.personNameComponents(from: self) else { // Not able to parse into a PersonNameComponent object return "" } formatter.style = .abbreviated nameInitials = Array(formatter.string(from: personNameComponents)) } var result = "" switch nameInitials.count { case let count where count >= 2: if let firstInitial = nameInitials.first { result.append(firstInitial) } if let lastInitial = nameInitials.last { result.append(lastInitial) } case let count where count == 1: if let firstInitial = nameInitials.first { result.append(firstInitial) } default: break } return result } Expected Results: The Thai, Hindi and Arabic initials should be those mentioned in https://developer.apple.com/documentation/foundation/personnamecomponentsformatter. Also the JD should be Jd for French. Actual Results: The initials are the empty string. Version/Build: Xcode 9.3, Swift 4.2. I'm not sure the version of Foundation. Configuration: Tested on simulator and iOS devices (debug and release).
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!