Created
November 27, 2019 07:21
-
-
Save wotjd/365e1f5358961fef18d7e5da36868337 to your computer and use it in GitHub Desktop.
convert raw id, string file to strings file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
id.txt example: | |
stringid1 | |
stringid2 | |
... | |
eng.txt example: | |
hello | |
world | |
glad | |
to | |
see | |
you | |
... | |
usage: | |
locate id.txt, eng.txt, convert_strings.swift to same folder | |
and run command `swift ./convert_strings.swift` | |
*/ | |
import Foundation | |
func convertToStrings(idfile: String, stringfile: String) -> String { | |
var result = "" | |
guard | |
let ids = try? String(contentsOfFile: idfile), | |
let strings = try? String(contentsOfFile: stringfile) | |
else { return result } | |
let idLines = ids.split(separator: "\n") | |
let stringLines = strings.split(separator: "\n") | |
let maxLine = min(idLines.count, stringLines.count) | |
var currentLine = 0 | |
while currentLine < maxLine { | |
result.append("\"\(idLines[currentLine])\" = \"\(stringLines[currentLine])\";\n") | |
currentLine += 1 | |
} | |
return result | |
} | |
try convertToStrings(idfile: "./id.txt", stringfile: "./eng.txt") | |
.write( | |
to: URL(fileURLWithPath: "./converted.strings"), | |
atomically: true, | |
encoding: .utf8 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment