Skip to content

Commit

Permalink
Add support for UTF-16 .strings files
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierLowmiller committed Apr 21, 2021
1 parent 28e2705 commit b0543d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/XcodeDeadStrings/DeadStringData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public struct DeadStringsData {

for (url, rangesToDelete) in stringsToDelete {
let data = FileManager.default.contents(atPath: url.path) ?? Data()
var contents = String(decoding: data, as: UTF8.self)
var contents = String(data: data, encoding: .utf8)
?? String(data: data, encoding: .utf16)
?? ""
for range in rangesToDelete {
contents.removeSubrange(range)
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/XcodeDeadStrings/ExtractLocalizedKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func extractLocalizedKeys(from contents: String, url: URL) -> [LocationStringRes

func extractLocalizedKeys(fromFileAt url: URL) -> [LocationStringResult] {
guard let data = FileManager.default.contents(atPath: url.path) else { return [] }
let contents = String(decoding: data, as: UTF8.self)
let contents = String(data: data, encoding: .utf8)
?? String(data: data, encoding: .utf16)
?? ""
return extractLocalizedKeys(from: contents, url: url)
}

Expand Down

0 comments on commit b0543d6

Please sign in to comment.