Skip to content

Commit c1dd99a

Browse files
authored
Merge pull request #18 from ranunez/feature/comparable
Cleans up sorting
2 parents c492333 + 357c80d commit c1dd99a

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

LocalizationEditor/Models/Localization.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Localization {
2929
}
3030

3131
let newTranslation = LocalizationString(key: key, value: value)
32-
translations = (translations + [newTranslation]).sorted(by: { $0.key < $1.key })
32+
translations = (translations + [newTranslation]).sorted()
3333
}
3434
}
3535

@@ -40,3 +40,9 @@ extension Localization: CustomStringConvertible {
4040
return language.uppercased()
4141
}
4242
}
43+
44+
extension Localization: Equatable {
45+
static func == (lhs: Localization, rhs: Localization) -> Bool {
46+
return lhs.language == rhs.language && lhs.translations == rhs.translations && lhs.path == rhs.path
47+
}
48+
}

LocalizationEditor/Models/LocalizationGroup.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ extension LocalizationGroup: CustomStringConvertible {
3030
return name
3131
}
3232
}
33+
34+
extension LocalizationGroup: Comparable {
35+
static func < (lhs: LocalizationGroup, rhs: LocalizationGroup) -> Bool {
36+
return lhs.name < rhs.name
37+
}
38+
39+
static func == (lhs: LocalizationGroup, rhs: LocalizationGroup) -> Bool {
40+
return lhs.name == rhs.name && lhs.path == rhs.path && lhs.localizations == rhs.localizations
41+
}
42+
}

LocalizationEditor/Models/LocalizationString.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ extension LocalizationString: CustomStringConvertible {
3232
return "\(key) = \(value)"
3333
}
3434
}
35+
36+
extension LocalizationString: Comparable {
37+
static func < (lhs: LocalizationString, rhs: LocalizationString) -> Bool {
38+
return lhs.key < rhs.key
39+
}
40+
41+
static func == (lhs: LocalizationString, rhs: LocalizationString) -> Bool {
42+
return lhs.key == rhs.key && lhs.value == rhs.value
43+
}
44+
}

LocalizationEditor/Providers/LocalizationProvider.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ final class LocalizationProvider {
7878
let lang = String(parts[parts.count - 2]).replacingOccurrences(of: ".lproj", with: "")
7979
return Localization(language: lang, translations: getLocalizationStrings(path: file.path), path: file.path)
8080
}), path: path)
81-
}).sorted(by: { $0.name < $1.name })
81+
}).sorted()
8282
}
8383

8484
// MARK: Internal implementation
@@ -99,8 +99,6 @@ final class LocalizationProvider {
9999

100100
Log.debug?.message("Found \(localizationStrings.count) keys for in \(path)")
101101

102-
return localizationStrings.sorted(by: { lhs, rhs -> Bool in
103-
lhs.key < rhs.key
104-
})
102+
return localizationStrings.sorted()
105103
}
106104
}

0 commit comments

Comments
 (0)