Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make localization error handling less strict #154

Merged
merged 12 commits into from
Nov 8, 2024
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.1"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.1"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.65.2")
],
targets: [
.target(
name: "HTMLKit",
dependencies: [
.product(name: "Collections", package: "swift-collections")
.product(name: "Collections", package: "swift-collections"),
.product(name: "Logging", package: "swift-log"),
],
exclude: ["Abstraction/README.md", "Framework/README.md"]
),
Expand Down
30 changes: 20 additions & 10 deletions Sources/HTMLKit/Framework/Localization/Locale.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// A type that represents a locale
///
/// A locale holds information about language, region and cultural preferences.
@_documentation(visibility: internal)
public struct Locale: Hashable {

/// A enumeration of possible tags
/// A enumeration of potential language tags
public enum Tag: String {

case arabic = "ar"
Expand Down Expand Up @@ -45,12 +47,16 @@ public struct Locale: Hashable {
case chinese = "zh"
}

/// The language code
/// The language code of the language
///
/// The language code represents the generic language.
public var language: String? {
return tag.components(separatedBy: "-").first
}

/// The region code
/// The region code of the language
///
/// The region code refers to the regional dialect of a language.
public var region: String? {

let components = tag.components(separatedBy: "-")
Expand All @@ -62,40 +68,44 @@ public struct Locale: Hashable {
return nil
}

/// The currency code
/// The currency code of the language
public var currencyCode: String? {
return currencyCodes[tag]
}

/// The currency symbol
/// The currency symbol of the language
public var currencySymbol: String? {
return currencySymbols[tag]
}

/// The decimal seperator
/// The decimal seperator of the language
public var decimalSeparator: String? {
return decimalSeparators[tag]
}

/// The date format
/// The date format of the language
public var dateFormat: String? {
return dateFormats[tag]
}

/// The time format
/// The time format of the language
public var timeFormat: String? {
return timeFormats[tag]
}

/// The locale identifier
public let tag: String

/// Initiates a locale
/// Initializes a locale
///
/// - Parameter tag: A locale tag e.g. en-US
public init(tag: String) {
self.tag = tag
}

/// Initiates a locale with a predefined tag
/// Initializes a locale with a predefined tag
///
/// - Parameter tag: A locale tag e.g. en-US
public init(tag: Tag) {
self.tag = tag.rawValue
}
Expand Down
13 changes: 7 additions & 6 deletions Sources/HTMLKit/Framework/Localization/Localizable.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
Abstract:
The file contains the default definition of a localizable element. It defines which properties and methods a content should come with.
*/

/// The protocol defines
/// A protocol that defines a type capable of being localized
@_documentation(visibility: internal)
public protocol Localizable {

/// Initializes a phrasing element intended for localization
///
/// - Parameters:
/// - localizedKey: The string key to be translated
/// - tableName: The name of the translation table
/// - interpolation: A variadic list of values used to replace placeholders within the translation string
init(_ localizedKey: String, tableName: String?, interpolation: Any...)
}
Loading
Loading