From fa2ce14dd819ab39d8a07cfe21a94ed1ad110d0d Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Tue, 9 Apr 2024 15:32:46 +1000 Subject: [PATCH] add code in script to check if the translation has the correct number of varables --- Scripts/LintLocalizableStrings.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Scripts/LintLocalizableStrings.swift b/Scripts/LintLocalizableStrings.swift index e943e0f03..b297c1e66 100755 --- a/Scripts/LintLocalizableStrings.swift +++ b/Scripts/LintLocalizableStrings.swift @@ -185,6 +185,17 @@ enum ScriptAction: String { missingKeysFromOtherFiles.forEach { missingKey, namesOfFilesItWasFound in Output.warning(file, "Phrase '\(missingKey)' is missing (found in: \(namesOfFilesItWasFound.joined(separator: ", ")))") } + + var maybeFaulty: [String] = [] + file.keyPhrase.forEach { key, phrase in + guard let original = projectState.primaryLocalizationFile.keyPhrase[key] else { return } + let numberOfVarablesOrignal = Regex.matches("\\{.*\\}", content: original.value).count + let numberOfVarablesPhrase = Regex.matches("\\{.*\\}", content: phrase.value).count + if numberOfVarablesPhrase != numberOfVarablesOrignal { + maybeFaulty.append(key) + } + } + maybeFaulty.forEach { key in Output.warning(file, "\(key) may be faulty.") } } // Process the source code