Skip to content

Commit

Permalink
Add comprehensive set of NumberingSystem constants
Browse files Browse the repository at this point in the history
  • Loading branch information
glebfann committed Nov 25, 2024
1 parent 5a39fc4 commit 5b8e8ff
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 10 deletions.
265 changes: 263 additions & 2 deletions Sources/FoundationEssentials/Locale/Locale+Components.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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") }
}
4 changes: 2 additions & 2 deletions Sources/FoundationEssentials/Locale/Locale_Unlocalized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ extension Locale.NumberingSystem {
if let numberingSystem, status.isSuccess {
self.init(String(cString: unumsys_getName(numberingSystem)))
} else {
self = .latn
self = .latin
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Locale.NumberingSystem> = [.latn, _lockedNumberingSystem(&state)]
// The result always has .latin and the locale's numbering system
var result: Set<Locale.NumberingSystem> = [.latin, _lockedNumberingSystem(&state)]

// https://www.unicode.org/reports/tr35/tr35-numbers.html#Numbering_Systems
let variants: [Locale.NumberingSystem] = [ "default", "native", "traditional", "finance" ]
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 5b8e8ff

Please sign in to comment.