Are there any tools to convert an Iphone localized string file to a string resources file that can be used in Android?
I think you might like this tool :
http://members.home.nl/bas.de.reuver/files/stringsconvert.html
Also this one, but it lacks some features (like converting whitespace in name) :
http://localise.biz/free/converter/ios-to-android
It is free, no need of registration, and you won't need to build your own script!
This is one of the areas where the Unix mindset and toolset comes in handy. I don't know what the iPhone format is like, but if it's what you say, with each value one per line, a simple sed
call could do this:
$ cat infile
"key"="value"
"key2"="value2"
$ sed 's/ *"\([^"]*\)" *= *"\([^"]*\)"/<string name="\1">\2<\/string>/' infile
<string name="key">value</string>
<string name="key2">value2</string>
$
I expect sed is available on your OSX install.
Ok i wrote my own little converter using a little bit from the code from alex.
public static void main(String[] args) throws IOException {
Scanner fileScanner =
new Scanner(new FileInputStream(args[0]), "utf-16");
Writer writer =
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
new File(args[1])), "UTF8"));
writer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?> <resources>");
while (fileScanner.hasNextLine()) {
String line = fileScanner.nextLine();
if (line.contains("=")) {
line = line.trim();
line = line.replace("\"", "");
line = line.replace(";", "");
String[] parts = line.split("=");
String nextLine =
"<string name=\"" + parts[0].trim() + "\">"
+ parts[1].trim() + "</string>";
System.out.println(nextLine);
writer.append(nextLine);
}
}
fileScanner.close();
writer.append("</resources>");
writer.close();
}
It was a little bit tricky to get Java to correctly read and write the UTF 16 input I got out of the xcode project but now it is working like a charm.