Jan*_*usz 14 port android localization
我有Iphone应用程序中使用的本地化字符串文件,我将其用于移植到Android.是否有任何工具通过从xcode项目中获取的文件并构建在android中使用字符串所需的xml?
由于apple文件是一个简单的键值文件,因此有一种工具可以转换此格式的字符串
"键" ="值"
对此:
<string name="key"> value </string>
这个工具应该很容易构建,但我很欣赏任何已经工作的工具.
我想你可能会喜欢这个工具:
http://members.home.nl/bas.de.reuver/files/stringsconvert.html
也是这个,但它缺少一些功能(比如在名称中转换空格):
http://localise.biz/free/converter/ios-to-android
它是免费的,无需注册,您不需要构建自己的脚本!
这是Unix思维模式和工具集派上用场的领域之一.我不知道iPhone格式是什么样的,但是如果它就是你所说的,每行每个值一个,一个简单的sed
调用可以做到这一点:
$ cat infile
"key"="value"
"key2"="value2"
$ sed 's/ *"\([^"]*\)" *= *"\([^"]*\)"/<string name="\1">\2<\/string>/' infile
<string name="key">value</string>
<string name="key2">value2</string>
$
Run Code Online (Sandbox Code Playgroud)
我希望你的OSX安装上可以使用sed.
好吧,我使用 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();
}
Run Code Online (Sandbox Code Playgroud)
让 Java 正确读取和写入我从 xcode 项目中获得的 UTF 16 输入有点棘手,但现在它工作得非常顺利。
归档时间: |
|
查看次数: |
5844 次 |
最近记录: |