mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-11 11:25:34 +00:00
Some checks are pending
Keyman Build Summary / Summarize build status checks (push) Waiting to run
37 lines
895 B
Swift
37 lines
895 B
Swift
/*
|
|
* Keyman is copyright (C) SIL Global. MIT License.
|
|
*
|
|
* Created by Shawn Schantz on 2025-12-19
|
|
*
|
|
* Value object for loading a language from kmp.json
|
|
*
|
|
*/
|
|
|
|
|
|
public struct LanguageSource: Identifiable, Decodable, Hashable, Equatable {
|
|
let name: String?
|
|
public let id: String
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case name
|
|
case id
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
self.name = try container.decodeIfPresent(String.self, forKey: .name)
|
|
|
|
let id = try container.decodeIfPresent(String.self, forKey: .id)
|
|
|
|
guard let validId = id, !validId.isEmpty else {
|
|
throw DecodingError.dataCorruptedError(
|
|
forKey: .id,
|
|
in: container,
|
|
debugDescription: "Language.id is required and cannot be empty."
|
|
)
|
|
}
|
|
|
|
self.id = validId
|
|
}
|
|
}
|