Skip to content

Instantly share code, notes, and snippets.

@billyto
Last active June 13, 2023 17:32
Show Gist options
  • Save billyto/34399cedb757b248ce2f to your computer and use it in GitHub Desktop.
Save billyto/34399cedb757b248ce2f to your computer and use it in GitHub Desktop.
convert localizable.string files to json format
#!/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