From 74cb8dc26b6e3ea87a57b7f00e7c56f1d0f88521 Mon Sep 17 00:00:00 2001 From: Martin Man Date: Tue, 11 Oct 2022 16:16:33 +0200 Subject: [PATCH 1/2] Use extractLocStrings -a to append new entries into temporary Localizable.strings file --- Sources/BartyCrouchKit/OldCommandLine/CodeCommander.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/BartyCrouchKit/OldCommandLine/CodeCommander.swift b/Sources/BartyCrouchKit/OldCommandLine/CodeCommander.swift index 9f2c3e1..7029007 100644 --- a/Sources/BartyCrouchKit/OldCommandLine/CodeCommander.swift +++ b/Sources/BartyCrouchKit/OldCommandLine/CodeCommander.swift @@ -32,7 +32,7 @@ public final class CodeCommander { let files = try findFiles(in: codeDirectoryPath, subpathsToIgnore: subpathsToIgnore) let customFunctionArgs = customFunction != nil ? ["-s", "\(customFunction!)"] : [] - let argumentsWithoutTheFiles = ["extractLocStrings"] + ["-o", stringsFilePath] + customFunctionArgs + ["-q"] + let argumentsWithoutTheFiles = ["extractLocStrings"] + ["-o", stringsFilePath] + customFunctionArgs + ["-q"] + ["-a"] let arguments = try appendFiles( files, From 7a30e15b98df687474f288a8a09783e3c28d1ef8 Mon Sep 17 00:00:00 2001 From: Martin Man Date: Tue, 11 Oct 2022 16:24:06 +0200 Subject: [PATCH 2/2] Properly handle string extraction logic when walking multiple codePaths dirs --- .../OldCommandLine/CommandLineActor.swift | 83 +++++++++---------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/Sources/BartyCrouchKit/OldCommandLine/CommandLineActor.swift b/Sources/BartyCrouchKit/OldCommandLine/CommandLineActor.swift index 4fc0b4c..a550473 100644 --- a/Sources/BartyCrouchKit/OldCommandLine/CommandLineActor.swift +++ b/Sources/BartyCrouchKit/OldCommandLine/CommandLineActor.swift @@ -308,21 +308,22 @@ public class CommandLineActor { usePlistArguments: Bool, ignoreKeys: [String] ) { - for inputDirectoryPath in inputDirectoryPaths { - let extractedStringsFileDirectory = inputDirectoryPath + "/tmpstrings/" + let extractedStringsFileDirectory = NSTemporaryDirectory() + let extractedLocalizableStringsFilePath = extractedStringsFileDirectory + "Localizable.strings" - do { - try FileManager.default.createDirectory( - atPath: extractedStringsFileDirectory, - withIntermediateDirectories: true, - attributes: nil - ) - } - catch { - print(error.localizedDescription, level: .error) - return - } + do { + try FileManager.default.createDirectory( + atPath: extractedStringsFileDirectory, + withIntermediateDirectories: true, + attributes: nil + ) + } + catch { + print(error.localizedDescription, level: .error) + return + } + for inputDirectoryPath in inputDirectoryPaths { do { try CodeCommander.shared.export( stringsFilesToPath: extractedStringsFileDirectory, @@ -331,47 +332,41 @@ public class CommandLineActor { usePlistArguments: usePlistArguments, subpathsToIgnore: subpathsToIgnore ) + print("Successfully updated strings file(s) of Code files.", level: .success, file: inputDirectoryPath) } catch { print("Could not extract strings from Code in directory '\(inputDirectoryPath)'.", level: .error) return } + } - let extractedLocalizableStringsFilePath = extractedStringsFileDirectory + "Localizable.strings" - guard FileManager.default.fileExists(atPath: extractedLocalizableStringsFilePath) else { - print("No localizations extracted from Code in directory '\(inputDirectoryPath)'.", level: .warning) - - // BUGFIX: Remove empty /tmpstrings/ folder again. - try? FileManager.default.removeItem(atPath: extractedStringsFileDirectory) - - return // NOTE: Expecting to see this only for empty project situations. - } + guard FileManager.default.fileExists(atPath: extractedLocalizableStringsFilePath) else { + print("No localizations extracted from Code.", level: .warning) + return // NOTE: Expecting to see this only for empty project situations. + } - for outputStringsFilePath in outputStringsFilePaths { - guard let stringsFileUpdater = StringsFileUpdater(path: outputStringsFilePath) else { continue } - - stringsFileUpdater.incrementallyUpdateKeys( - withStringsFileAtPath: extractedLocalizableStringsFilePath, - addNewValuesAsEmpty: !defaultToKeys, - ignoreBaseKeysAndComment: ignoreKeys, - override: override, - keepExistingKeys: additive, - overrideComments: overrideComments, - keepWhitespaceSurroundings: unstripped - ) + for outputStringsFilePath in outputStringsFilePaths { + guard let stringsFileUpdater = StringsFileUpdater(path: outputStringsFilePath) else { continue } - if verbose { print("Incrementally updated keys of file '\(outputStringsFilePath)'.", level: .info) } - } + stringsFileUpdater.incrementallyUpdateKeys( + withStringsFileAtPath: extractedLocalizableStringsFilePath, + addNewValuesAsEmpty: !defaultToKeys, + ignoreBaseKeysAndComment: ignoreKeys, + override: override, + keepExistingKeys: additive, + overrideComments: overrideComments, + keepWhitespaceSurroundings: unstripped + ) - do { - try FileManager.default.removeItem(atPath: extractedStringsFileDirectory) - } - catch { - print("Temporary strings files couldn't be deleted at path '\(extractedStringsFileDirectory)'", level: .error) - return - } + if verbose { print("Incrementally updated keys of file '\(outputStringsFilePath)'.", level: .info) } + } - print("Successfully updated strings file(s) of Code files.", level: .success, file: inputDirectoryPath) + do { + try FileManager.default.removeItem(atPath: extractedLocalizableStringsFilePath) + } + catch { + print("Temporary strings files couldn't be deleted at path '\(extractedLocalizableStringsFilePath)'", level: .error) + return } }