很抱歉再次打扰。我正在实现一个应用程序,在 xcode 5 中本地化英语和日语,使用由 André Pinto 创建的脚本文件,基于SIngle Storyboard for multiple languages。好吧,在升级到 xcode 5(我的意思是 xcode 4.6)之前,一切正常。但是从 xcode 5 开始,运行脚本文件时会出现此错误:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.ibtool.errors</key>
<array>
<dict>
<key>description</key>
<string>Interface Builder could not open the document "xx.storyboard" because it does not exist.</string>
</dict>
</array>
</dict>
</plist>
Iconv: ./xx/Base.lproj/xx.strings.new: No such file or directory
Rm: ./xx/Base.lproj/xx.strings.new: No such file or directory
Merging xx.strings changes for en.lproj...
Merging xx.strings changes for ja.lproj...
Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure
在故事板中,有 2 个子文件:xx.storyboard(Base) 和 xx.storyboard(Japanese)
在第一次构建中,没有发生错误。一切都很顺利。应用本地化非常好。
在第二个版本中,我对故事板进行了一些更改(添加了一些新功能),然后出现错误。此外,xx.storyboard(Japanese) 变成空白,这很奇怪。我花了很多精力翻译那些东西,现在我必须再做一次......
我认为脚本,strings.new 和 strings.old 有一些问题......
这是脚本:
#!/bin/sh
# Update storyboard string files
#
# by 2013 André Pinto andredsp@gmail.com
# based on http://forums.macrumors.com/showthread.php?t=1467446
storyboardExt=".storyboard"
stringsExt=".strings"
newStringsExt=".strings.new"
oldStringsExt=".strings.old"
localeDirExt=".lproj"
baselprojName="Base.lproj"
# Find Base internationalization folders
find . -name "$baselprojName" | while read baselprojPath
do
# Get Base project dir
baselprojDir=$(dirname "$baselprojPath")
# Find storyboard file full path inside base project folder
find "$baselprojPath" -name "*$storyboardExt" | while read storyboardPath
do
# Get Base strings file full path
baseStringsPath=$(echo "$storyboardPath" | sed "s/$storyboardExt/$stringsExt/")
# Get storyboard file name and folder
storyboardFile=$(basename "$storyboardPath")
storyboardDir=$(dirname "$storyboardPath")
# Create strings file only when storyboard file newer
newer=$(find "$storyboardPath" -prune -newer "$baseStringsPath")
[ -f "$baseStringsPath" -a -z "$newer" ] && {
echo "$storyboardFile file not modified."
continue
}
# Get New Base strings file full path and strings file name
newBaseStringsPath=$(echo "$storyboardPath" | sed "s/$storyboardExt/$newStringsExt/")
stringsFile=$(basename "$baseStringsPath")
echo "Creating default $stringsFile for $storyboardFile..."
ibtool --export-strings-file "$newBaseStringsPath" "$storyboardPath"
iconv -f UTF-16 -t UTF-8 "$newBaseStringsPath" > "$baseStringsPath"
rm "$newBaseStringsPath"
# Get all locale strings folder with same parent as Base
ls -d "$baselprojDir/"*"$localeDirExt" | while read localeStringsDir
do
# Skip Base strings folder
[ "$localeStringsDir" = "$storyboardDir" ] && continue
localeDir=$(basename "$localeStringsDir")
localeStringsPath="$localeStringsDir/$stringsFile"
# Just copy base strings file on first time
if [ ! -e "$localeStringsPath" ]; then
echo "Copying default $stringsFile for $localeDir..."
cp "$baseStringsPath" "$localeStringsPath"
else
echo "Merging $stringsFile changes for $localeDir..."
oldLocaleStringsPath=$(echo "$localeStringsPath" | sed "s/$stringsExt/$oldStringsExt/")
cp "$localeStringsPath" "$oldLocaleStringsPath"
# Merge baseStringsPath to localeStringsPath
awk '
NR == FNR && /^\/\*/ {
x=$0
getline
a[x]=$0
next
}
/^\/\*/ {
x=$0
print
getline
$0=a[x]?a[x]:$0
printf $0"\n\n"
}' "$oldLocaleStringsPath" "$baseStringsPath" > "$localeStringsPath"
rm "$oldLocaleStringsPath"
fi
done
done
done
Localizable.strings 和 InfoPlist.strings 还是不错的。
任何有这种事情经验的人请帮助我......这是xcode,脚本文件或xx.strings文件的东西吗?我不明白...
我可以直接问脚本的创建者,但我认为在这里发布问题会更好。我是这样的情人:)