Skip to content

Commit

Permalink
Add warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
roddymunro committed Mar 15, 2024
1 parent aa2ca71 commit b70d04a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Sources/SwiftPolyglot/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func checkTranslations(in fileURL: URL, for languages: [String]) {
let jsonDict = jsonObject as? [String: Any],
let strings = jsonDict["strings"] as? [String: [String: Any]]
else {
print("Could not process file: \(fileURL.path)")
print("::warning file=\(fileURL.path)::Could not process file at path: \(fileURL.path)")
return
}

for (originalString, translations) in strings {
guard let localizations = translations["localizations"] as? [String: [String: Any]] else {
print("Warning: '\(originalString)' is not translated in any language in file: \(fileURL.absoluteString)")
logWarning(file: fileURL.path, message: "'\(originalString)' is not translated in any language in file: \(fileURL.path)")
missingTranslations = true
continue
}
Expand All @@ -36,7 +36,7 @@ func checkTranslations(in fileURL: URL, for languages: [String]) {
let state = stringUnit["state"] as? String, state == "translated"
{
} else {
print("Warning: '\(originalString)' is missing or not translated in \(lang) in file: \(fileURL.absoluteString)")
logWarning(file: fileURL.path, message: "'\(originalString)' is missing or not translated in \(lang) in file: \(fileURL.path)")
missingTranslations = true
}
}
Expand All @@ -54,6 +54,14 @@ func searchDirectory(_ dirPath: String) {
}
}

func logWarning(file: String, message: String) {
if errorOnMissing {
print("::error file=\(file)::\(message)")
} else {
print("::warning file=\(file)::\(message)")
}
}

searchDirectory(currentDirectoryPath)

if missingTranslations, errorOnMissing {
Expand Down

0 comments on commit b70d04a

Please sign in to comment.