Skip to content

Commit

Permalink
Replace DictionaryWrapper by using CodingKeyRepresentable on key type…
Browse files Browse the repository at this point in the history
…s instead (#54)
  • Loading branch information
liamnichols authored Apr 12, 2024
1 parent 839f2e4 commit 8a973a7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 110 deletions.
2 changes: 1 addition & 1 deletion Sources/StringCatalog/Types/StringEntry.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public struct StringEntry: Codable {
public typealias Localizations = DictionaryWrapper<StringLanguage, StringLocalization>
public typealias Localizations = [StringLanguage: StringLocalization]

public var comment: String?
public var extractionState: StringExtractionState?
Expand Down
2 changes: 1 addition & 1 deletion Sources/StringCatalog/Types/StringLanguage.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct StringLanguage: Codable, Hashable, RawRepresentable, ExpressibleByStringLiteral {
public struct StringLanguage: Codable, Hashable, RawRepresentable, ExpressibleByStringLiteral, CodingKeyRepresentable {
public let rawValue: String

public init(rawValue: String) {
Expand Down
10 changes: 5 additions & 5 deletions Sources/StringCatalog/Types/StringVariations.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Foundation

public struct StringVariations: Codable {
public let device: DictionaryWrapper<DeviceKey, StringVariation>?
public let plural: DictionaryWrapper<PluralKey, StringVariation>?
public let device: [DeviceKey: StringVariation]?
public let plural: [PluralKey: StringVariation]?

public init(device: DictionaryWrapper<DeviceKey, StringVariation>?, plural: DictionaryWrapper<PluralKey, StringVariation>?) {
public init(device: [DeviceKey: StringVariation]?, plural: [PluralKey: StringVariation]?) {
self.device = device
self.plural = plural
}
}

extension StringVariations {
public struct DeviceKey: Codable, Hashable, RawRepresentable, ExpressibleByStringLiteral {
public struct DeviceKey: Codable, Hashable, RawRepresentable, ExpressibleByStringLiteral, CodingKeyRepresentable {
public let rawValue: String

public init(rawValue: String) {
Expand All @@ -32,7 +32,7 @@ extension StringVariations {
public static let other = Self(rawValue: "other")
}

public struct PluralKey: Codable, Hashable, RawRepresentable, ExpressibleByStringLiteral {
public struct PluralKey: Codable, Hashable, RawRepresentable, ExpressibleByStringLiteral, CodingKeyRepresentable {
public let rawValue: String

public init(rawValue: String) {
Expand Down
101 changes: 0 additions & 101 deletions Sources/StringCatalog/Utilities/DictionaryWrapper.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/StringExtractor/Resource+StringUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ extension Resource {
}
}

private extension DictionaryWrapper where Key == StringVariations.DeviceKey, Value == StringVariation {
private extension Dictionary where Key == StringVariations.DeviceKey, Value == StringVariation {
var preferredDeviceVariation: StringVariation? {
self[.other] ?? self.values.first
}
}

private extension DictionaryWrapper where Key == StringVariations.PluralKey, Value == StringVariation {
private extension Dictionary where Key == StringVariations.PluralKey, Value == StringVariation {
var preferredPluralVariation: StringVariation? {
self[.other] ?? self[.one] ?? self.values.first
}
Expand Down

0 comments on commit 8a973a7

Please sign in to comment.