Last active
June 13, 2023 17:32
-
-
Save billyto/34399cedb757b248ce2f to your computer and use it in GitHub Desktop.
convert localizable.string files to json format
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
#!/usr/bin/env swift | |
//FIRST: chmod +x localized2JSON.swift | |
//USE: ./localize-strings2json.swift localizable.strings strings.json | |
//TODO: error checking for parameters and files | |
//TODO: --help -h | |
//TODO: separate groups of string in dictionaries? | |
import Foundation | |
let params = Process.arguments | |
let stringFilename = params[1] | |
let jsonFile = params[2] | |
print("Will read from \(stringFilename) and return \(jsonFile)") | |
if let dict = NSDictionary(contentsOfFile: stringFilename)! | |
do { | |
let json = try NSJSONSerialization.dataWithJSONObject(dict, options: .PrettyPrinted) | |
let dataString = NSString(data: json, encoding: NSUTF8StringEncoding)! | |
print("converting....") | |
//writing | |
try dataString.writeToFile(jsonFile, atomically: false, encoding: NSUTF8StringEncoding) | |
} catch{ | |
print("failed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment