Skip to content

Commit dafbf0a

Browse files
committed
Merge branch 'feat/frizlab/swiftui_replacements' into develop
2 parents 1543d63 + d00a951 commit dafbf0a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

LocMapper CLI/Commands/UpdateXcodeStringsFromCode.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ struct UpdateXcodeStringsFromCode : ParsableCommand {
8787
@Argument
8888
var rootFolder: String
8989

90-
@Argument(help: #"Pass “MY_TABLE MyTable” (two arguments) to convert `NSLocalizedString("MyString", tableName: MY_TABLE, comment: "This comment!")` into `NSLocalizedString("MyString", tableName: "MyTable", comment: "This comment!")` for instance."#)
90+
@Argument(help: #"""
91+
When using genstrings in UIKit/AppKit mode, passing e.g. “MY_TABLE MyTable” (two arguments) will convert `NSLocalizedString("MyString", tableName: MY_TABLE, comment: "This comment!")` into `NSLocalizedString("MyString", tableName: "MyTable", comment: "This comment!")`.
92+
When using genstrings in SwiftUI mode, the same is done, but the replacement will not be quoted (e.g. with “MyText Text”, `MyText("loc-key")` will be replaced by `Text("loc-key")`).
93+
"""#)
9194
var tableDefinesToValuesMapping = [String]()
9295

9396
func run() throws {
@@ -267,7 +270,18 @@ struct UpdateXcodeStringsFromCode : ParsableCommand {
267270
let objcMark = (Set(arrayLiteral: "m", "mm").contains(codeURL.pathExtension) ? "@" : "")
268271
var code = try String(contentsOf: codeURL)
269272
for (regex, value) in regexesAndValues {
270-
code = regex.stringByReplacingMatches(in: code, options: [], range: NSRange(code.startIndex..<code.endIndex, in: code), withTemplate: objcMark + "\"" + NSRegularExpression.escapedTemplate(for: value) + "\"")
273+
code = regex.stringByReplacingMatches(
274+
in: code,
275+
options: [],
276+
range: NSRange(code.startIndex..<code.endIndex, in: code),
277+
withTemplate: {
278+
if !swiftUI {
279+
objcMark + "\"" + NSRegularExpression.escapedTemplate(for: value) + "\""
280+
} else {
281+
NSRegularExpression.escapedTemplate(for: value)
282+
}
283+
}()
284+
)
271285
}
272286
try Data(code.utf8).write(to: codeURL)
273287
codeFilePaths.append(codeURL.path)

0 commit comments

Comments
 (0)