【发布时间】:2009-06-17 14:20:58
【问题描述】:
如果您在 Settings.bundle 中构建子窗格,您最终会得到几个 .plist 文件。当需要本地化您的项目时,您会发现创建相应的 .strings 文件有点乏味(我知道我会这样做)。
这是一个方便的列表 bash 脚本,它将 (i) 查找标签,(ii) 提取以下标签的内容,然后 (iii) 将该值输出到 "string" = "string" 格式的文本文件ibtool 需要。
您将输入和输出文件名作为参数传递。
#!/bin/sh
echo "// Generated by plist2strings. Manual edits will be overwritten the next time this script runs.\n/* A single strings file, whose title is specified in your preferences schema. The strings files provide the localized content to display to the user for each of your preferences. */\n" > plist2stringstmp
sed -n '
# look for a "#" at the end of the line
/<key>Title<\/key>$/ {
# Found one - now read in the next line
N
# delete the "#" and the new line character,
s/.*<\(string\)>\(.*\)<\/\1>/"\2" = "\2"/gp
}' $1 > plist2stringstmp2
cat plist2stringstmp plist2stringstmp2 > $2
rm plist2stringstmp plist2stringstmp2
复制-N-粘贴到文本文件中。我将我的保存为 plist2strings。一定要给它执行权限。例如,在终端执行:
macbook:~ foo$ chmod 755 plist2strings
要从 Settings.bundle 目录的根目录执行脚本(如果保存到您的用户文件夹),只需使用以下语法:
macbook:~ foo$ ~/plist2strings mysettings.plist en.lprog/mysettings.strings
如果 mysettings.strings 不在该文件夹中,它将创建它。如果它已经存在,它会自动覆盖它而不发出警告。
希望有人觉得这很有用。并且随意使用(和滥用)你认为合适的(警告购买者;-)。如果您做出任何有用的更改,请考虑将它们发回此处以供其他人欣赏。
本地化愉快!
~扎克
【问题讨论】:
-
有一个非常相似的问题 - 它有一个非常好的解决方案。 stackoverflow.com/questions/6271715/…
标签: iphone cocoa-touch localization internationalization settings.bundle