From 5b8e8ffb534ab739f707d44fe482fb8d72cc35bf Mon Sep 17 00:00:00 2001 From: Gleb Fandeev Date: Thu, 21 Nov 2024 17:23:11 +0300 Subject: [PATCH] Add comprehensive set of NumberingSystem constants --- .../Locale/Locale+Components.swift | 265 +++++++++++++++++- .../Locale/Locale_Unlocalized.swift | 4 +- .../Locale/Locale+Components_ICU.swift | 2 +- .../Locale/Locale_ICU.swift | 6 +- .../LocaleComponentsTests.swift | 2 +- .../LocaleTests.swift | 2 +- 6 files changed, 271 insertions(+), 10 deletions(-) diff --git a/Sources/FoundationEssentials/Locale/Locale+Components.swift b/Sources/FoundationEssentials/Locale/Locale+Components.swift index 42fce9df9..3a6e8da68 100644 --- a/Sources/FoundationEssentials/Locale/Locale+Components.swift +++ b/Sources/FoundationEssentials/Locale/Locale+Components.swift @@ -508,8 +508,6 @@ extension Locale { _normalizedIdentifier = identifier.lowercased() } - package static let latn = NumberingSystem("latn") - public func hash(into hasher: inout Hasher) { hasher.combine(_normalizedIdentifier) } @@ -2041,3 +2039,266 @@ extension Locale.Script { public static var tibetan: Locale.Script { Locale.Script("Tibt") } } +@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) +extension Locale.NumberingSystem { + @_alwaysEmitIntoClient + public static var adlam: Locale.NumberingSystem { Locale.NumberingSystem("adlm") } + + @_alwaysEmitIntoClient + public static var ahom: Locale.NumberingSystem { Locale.NumberingSystem("ahom") } + + @_alwaysEmitIntoClient + public static var arabic: Locale.NumberingSystem { Locale.NumberingSystem("arab") } + + @_alwaysEmitIntoClient + public static var arabicExtended: Locale.NumberingSystem { Locale.NumberingSystem("arabext") } + + @_alwaysEmitIntoClient + public static var armenianUpper: Locale.NumberingSystem { Locale.NumberingSystem("armn") } + + @_alwaysEmitIntoClient + public static var armenianLower: Locale.NumberingSystem { Locale.NumberingSystem("armnlow") } + + @_alwaysEmitIntoClient + public static var balinese: Locale.NumberingSystem { Locale.NumberingSystem("bali") } + + @_alwaysEmitIntoClient + public static var bengali: Locale.NumberingSystem { Locale.NumberingSystem("beng") } + + @_alwaysEmitIntoClient + public static var bhaiksuki: Locale.NumberingSystem { Locale.NumberingSystem("bhks") } + + @_alwaysEmitIntoClient + public static var brahmi: Locale.NumberingSystem { Locale.NumberingSystem("brah") } + + @_alwaysEmitIntoClient + public static var chakma: Locale.NumberingSystem { Locale.NumberingSystem("cakm") } + + @_alwaysEmitIntoClient + public static var cham: Locale.NumberingSystem { Locale.NumberingSystem("cham") } + + @_alwaysEmitIntoClient + public static var cyrillic: Locale.NumberingSystem { Locale.NumberingSystem("cyrl") } + + @_alwaysEmitIntoClient + public static var devanagari: Locale.NumberingSystem { Locale.NumberingSystem("deva") } + + @_alwaysEmitIntoClient + public static var divesAkuru: Locale.NumberingSystem { Locale.NumberingSystem("diak") } + + @_alwaysEmitIntoClient + public static var ethiopic: Locale.NumberingSystem { Locale.NumberingSystem("ethi") } + + @_alwaysEmitIntoClient + public static var financial: Locale.NumberingSystem { Locale.NumberingSystem("finance") } + + @_alwaysEmitIntoClient + public static var fullwide: Locale.NumberingSystem { Locale.NumberingSystem("fullwide") } + + @_alwaysEmitIntoClient + public static var georgian: Locale.NumberingSystem { Locale.NumberingSystem("geor") } + + @_alwaysEmitIntoClient + public static var gunjalaGondi: Locale.NumberingSystem { Locale.NumberingSystem("gong") } + + @_alwaysEmitIntoClient + public static var masaramGondi: Locale.NumberingSystem { Locale.NumberingSystem("gonm") } + + @_alwaysEmitIntoClient + public static var greekUpper: Locale.NumberingSystem { Locale.NumberingSystem("grek") } + + @_alwaysEmitIntoClient + public static var greekLower: Locale.NumberingSystem { Locale.NumberingSystem("greklow") } + + @_alwaysEmitIntoClient + public static var gujarati: Locale.NumberingSystem { Locale.NumberingSystem("gujr") } + + @_alwaysEmitIntoClient + public static var gurmukhi: Locale.NumberingSystem { Locale.NumberingSystem("guru") } + + @_alwaysEmitIntoClient + public static var hanidays: Locale.NumberingSystem { Locale.NumberingSystem("hanidays") } + + @_alwaysEmitIntoClient + public static var hanidecimal: Locale.NumberingSystem { Locale.NumberingSystem("hanidec") } + + @_alwaysEmitIntoClient + public static var simplifiedChinese: Locale.NumberingSystem { Locale.NumberingSystem("hans") } + + @_alwaysEmitIntoClient + public static var simplifiedChineseFinancial: Locale.NumberingSystem { Locale.NumberingSystem("hansfin") } + + @_alwaysEmitIntoClient + public static var traditionalChinese: Locale.NumberingSystem { Locale.NumberingSystem("hant") } + + @_alwaysEmitIntoClient + public static var traditionalChineseFinancial: Locale.NumberingSystem { Locale.NumberingSystem("hantfin") } + + @_alwaysEmitIntoClient + public static var hebrew: Locale.NumberingSystem { Locale.NumberingSystem("hebr") } + + @_alwaysEmitIntoClient + public static var pahawhHmong: Locale.NumberingSystem { Locale.NumberingSystem("hmng") } + + @_alwaysEmitIntoClient + public static var nyiakengPuachueHmong: Locale.NumberingSystem { Locale.NumberingSystem("hmnp") } + + @_alwaysEmitIntoClient + public static var javanese: Locale.NumberingSystem { Locale.NumberingSystem("java") } + + @_alwaysEmitIntoClient + public static var japanese: Locale.NumberingSystem { Locale.NumberingSystem("jpan") } + + @_alwaysEmitIntoClient + public static var japaneseFinancial: Locale.NumberingSystem { Locale.NumberingSystem("jpanfin") } + + @_alwaysEmitIntoClient + public static var japaneseYear: Locale.NumberingSystem { Locale.NumberingSystem("jpanyear") } + + @_alwaysEmitIntoClient + public static var kayahLi: Locale.NumberingSystem { Locale.NumberingSystem("kali") } + + @_alwaysEmitIntoClient + public static var khmer: Locale.NumberingSystem { Locale.NumberingSystem("khmr") } + + @_alwaysEmitIntoClient + public static var kannada: Locale.NumberingSystem { Locale.NumberingSystem("knda") } + + @_alwaysEmitIntoClient + public static var taiThamHora: Locale.NumberingSystem { Locale.NumberingSystem("lana") } + + @_alwaysEmitIntoClient + public static var taiThamTham: Locale.NumberingSystem { Locale.NumberingSystem("lanatham") } + + @_alwaysEmitIntoClient + public static var lao: Locale.NumberingSystem { Locale.NumberingSystem("laoo") } + + @_alwaysEmitIntoClient + public static var latin: Locale.NumberingSystem { Locale.NumberingSystem("latn") } + + @_alwaysEmitIntoClient + public static var lepcha: Locale.NumberingSystem { Locale.NumberingSystem("lepc") } + + @_alwaysEmitIntoClient + public static var limbu: Locale.NumberingSystem { Locale.NumberingSystem("limb") } + + @_alwaysEmitIntoClient + public static var mathBold: Locale.NumberingSystem { Locale.NumberingSystem("mathbold") } + + @_alwaysEmitIntoClient + public static var mathDoubleStruck: Locale.NumberingSystem { Locale.NumberingSystem("mathdbl") } + + @_alwaysEmitIntoClient + public static var mathMonospace: Locale.NumberingSystem { Locale.NumberingSystem("mathmono") } + + @_alwaysEmitIntoClient + public static var mathSansSerifBold: Locale.NumberingSystem { Locale.NumberingSystem("mathsanb") } + + @_alwaysEmitIntoClient + public static var mathSansSerif: Locale.NumberingSystem { Locale.NumberingSystem("mathsans") } + + @_alwaysEmitIntoClient + public static var malayalam: Locale.NumberingSystem { Locale.NumberingSystem("mlym") } + + @_alwaysEmitIntoClient + public static var modi: Locale.NumberingSystem { Locale.NumberingSystem("modi") } + + @_alwaysEmitIntoClient + public static var mongolian: Locale.NumberingSystem { Locale.NumberingSystem("mong") } + + @_alwaysEmitIntoClient + public static var mro: Locale.NumberingSystem { Locale.NumberingSystem("mroo") } + + @_alwaysEmitIntoClient + public static var meeteiMayek: Locale.NumberingSystem { Locale.NumberingSystem("mtei") } + + @_alwaysEmitIntoClient + public static var myanmar: Locale.NumberingSystem { Locale.NumberingSystem("mymr") } + + @_alwaysEmitIntoClient + public static var myanmarShan: Locale.NumberingSystem { Locale.NumberingSystem("mymrshan") } + + @_alwaysEmitIntoClient + public static var myanmarTaiLaing: Locale.NumberingSystem { Locale.NumberingSystem("mymrtlng") } + + @_alwaysEmitIntoClient + public static var native: Locale.NumberingSystem { Locale.NumberingSystem("native") } + + @_alwaysEmitIntoClient + public static var newa: Locale.NumberingSystem { Locale.NumberingSystem("newa") } + + @_alwaysEmitIntoClient + public static var nko: Locale.NumberingSystem { Locale.NumberingSystem("nkoo") } + + @_alwaysEmitIntoClient + public static var olChiki: Locale.NumberingSystem { Locale.NumberingSystem("olck") } + + @_alwaysEmitIntoClient + public static var oriya: Locale.NumberingSystem { Locale.NumberingSystem("orya") } + + @_alwaysEmitIntoClient + public static var osmanya: Locale.NumberingSystem { Locale.NumberingSystem("osma") } + + @_alwaysEmitIntoClient + public static var hanifiRohingya: Locale.NumberingSystem { Locale.NumberingSystem("rohg") } + + @_alwaysEmitIntoClient + public static var romanUpper: Locale.NumberingSystem { Locale.NumberingSystem("roman") } + + @_alwaysEmitIntoClient + public static var romanLower: Locale.NumberingSystem { Locale.NumberingSystem("romanlow") } + + @_alwaysEmitIntoClient + public static var saurashtra: Locale.NumberingSystem { Locale.NumberingSystem("saur") } + + @_alwaysEmitIntoClient + public static var sharada: Locale.NumberingSystem { Locale.NumberingSystem("shrd") } + + @_alwaysEmitIntoClient + public static var khudawadi: Locale.NumberingSystem { Locale.NumberingSystem("sind") } + + @_alwaysEmitIntoClient + public static var sinhala: Locale.NumberingSystem { Locale.NumberingSystem("sinh") } + + @_alwaysEmitIntoClient + public static var soraSompeng: Locale.NumberingSystem { Locale.NumberingSystem("sora") } + + @_alwaysEmitIntoClient + public static var sundanese: Locale.NumberingSystem { Locale.NumberingSystem("sund") } + + @_alwaysEmitIntoClient + public static var takri: Locale.NumberingSystem { Locale.NumberingSystem("takr") } + + @_alwaysEmitIntoClient + public static var newTaiLue: Locale.NumberingSystem { Locale.NumberingSystem("talu") } + + @_alwaysEmitIntoClient + public static var tamil: Locale.NumberingSystem { Locale.NumberingSystem("taml") } + + @_alwaysEmitIntoClient + public static var modernTamil: Locale.NumberingSystem { Locale.NumberingSystem("tamldec") } + + @_alwaysEmitIntoClient + public static var telugu: Locale.NumberingSystem { Locale.NumberingSystem("telu") } + + @_alwaysEmitIntoClient + public static var thai: Locale.NumberingSystem { Locale.NumberingSystem("thai") } + + @_alwaysEmitIntoClient + public static var tirhuta: Locale.NumberingSystem { Locale.NumberingSystem("tirh") } + + @_alwaysEmitIntoClient + public static var tibetan: Locale.NumberingSystem { Locale.NumberingSystem("tibt") } + + @_alwaysEmitIntoClient + public static var traditional: Locale.NumberingSystem { Locale.NumberingSystem("traditio") } + + @_alwaysEmitIntoClient + public static var vai: Locale.NumberingSystem { Locale.NumberingSystem("vaii") } + + @_alwaysEmitIntoClient + public static var warangCiti: Locale.NumberingSystem { Locale.NumberingSystem("wara") } + + @_alwaysEmitIntoClient + public static var wancho: Locale.NumberingSystem { Locale.NumberingSystem("wcho") } +} diff --git a/Sources/FoundationEssentials/Locale/Locale_Unlocalized.swift b/Sources/FoundationEssentials/Locale/Locale_Unlocalized.swift index 5f8b6fb29..f25b08238 100644 --- a/Sources/FoundationEssentials/Locale/Locale_Unlocalized.swift +++ b/Sources/FoundationEssentials/Locale/Locale_Unlocalized.swift @@ -162,11 +162,11 @@ internal final class _LocaleUnlocalized : _LocaleProtocol, @unchecked Sendable { } var numberingSystem: Locale.NumberingSystem { - .latn + .latin } var availableNumberingSystems: [Locale.NumberingSystem] { - [.latn] + [.latin] } var firstDayOfWeek: Locale.Weekday { diff --git a/Sources/FoundationInternationalization/Locale/Locale+Components_ICU.swift b/Sources/FoundationInternationalization/Locale/Locale+Components_ICU.swift index 5bb092e82..7345a0be2 100644 --- a/Sources/FoundationInternationalization/Locale/Locale+Components_ICU.swift +++ b/Sources/FoundationInternationalization/Locale/Locale+Components_ICU.swift @@ -453,7 +453,7 @@ extension Locale.NumberingSystem { if let numberingSystem, status.isSuccess { self.init(String(cString: unumsys_getName(numberingSystem))) } else { - self = .latn + self = .latin } } } diff --git a/Sources/FoundationInternationalization/Locale/Locale_ICU.swift b/Sources/FoundationInternationalization/Locale/Locale_ICU.swift index 745459a60..ef8d7cb1f 100644 --- a/Sources/FoundationInternationalization/Locale/Locale_ICU.swift +++ b/Sources/FoundationInternationalization/Locale/Locale_ICU.swift @@ -1431,8 +1431,8 @@ internal final class _LocaleICU: _LocaleProtocol, Sendable { return systems } - // The result always has .latn and the locale's numbering system - var result: Set = [.latn, _lockedNumberingSystem(&state)] + // The result always has .latin and the locale's numbering system + var result: Set = [.latin, _lockedNumberingSystem(&state)] // https://www.unicode.org/reports/tr35/tr35-numbers.html#Numbering_Systems let variants: [Locale.NumberingSystem] = [ "default", "native", "traditional", "finance" ] @@ -1631,7 +1631,7 @@ extension Locale { return numbering } - return Locale.NumberingSystem.defaultNumberingSystem(for: localeID) ?? .latn + return Locale.NumberingSystem.defaultNumberingSystem(for: localeID) ?? .latin } static func localeIdentifierWithLikelySubtags(_ localeID: String) -> String { diff --git a/Tests/FoundationInternationalizationTests/LocaleComponentsTests.swift b/Tests/FoundationInternationalizationTests/LocaleComponentsTests.swift index e589d8009..b32e3c287 100644 --- a/Tests/FoundationInternationalizationTests/LocaleComponentsTests.swift +++ b/Tests/FoundationInternationalizationTests/LocaleComponentsTests.swift @@ -444,7 +444,7 @@ final class LocaleCodableTests: XCTestCase { } do { - let codableObj = Locale.NumberingSystem.latn + let codableObj = Locale.NumberingSystem.latin let decoded = _testRoundtripCoding(codableObj, identifier: codableObj.identifier, normalizedIdentifier: codableObj._normalizedIdentifier) XCTAssertEqual(decoded?.identifier, codableObj.identifier) XCTAssertEqual(decoded?._normalizedIdentifier, codableObj._normalizedIdentifier) diff --git a/Tests/FoundationInternationalizationTests/LocaleTests.swift b/Tests/FoundationInternationalizationTests/LocaleTests.swift index c9dbdfa7f..834f989a6 100644 --- a/Tests/FoundationInternationalizationTests/LocaleTests.swift +++ b/Tests/FoundationInternationalizationTests/LocaleTests.swift @@ -190,7 +190,7 @@ final class LocaleTests : XCTestCase { verify(cldr: "fr_u_cu_eur_nu_latn", bcp47: "fr-u-cu-eur-nu-latn", icu: "fr@currency=eur;numbers=latn") { var localeComponents = Locale.Components(languageCode: .french) localeComponents.currency = "eur" - localeComponents.numberingSystem = .latn + localeComponents.numberingSystem = .latin return localeComponents }