From b70d04a56829216ff463e7a9f997051ac8178380 Mon Sep 17 00:00:00 2001 From: Roddy Munro Date: Fri, 15 Mar 2024 18:43:03 -0300 Subject: [PATCH] Add warnings --- Sources/SwiftPolyglot/main.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftPolyglot/main.swift b/Sources/SwiftPolyglot/main.swift index 4aacad6..3fa38e5 100755 --- a/Sources/SwiftPolyglot/main.swift +++ b/Sources/SwiftPolyglot/main.swift @@ -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 } @@ -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 } } @@ -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 {