【问题标题】:xcode 5 localize storyboard with script delete *.strings file?xcode 5 使用脚本删除 *.strings 文件本地化情节提要?
【发布时间】:2013-11-03 23:59:43
【问题描述】:

抱歉又打扰了。 我正在使用 André Pinto 基于SIngle Storyboard for multiple languages 创建的脚本文件实现一个应用程序,在 xcode 5 中本地化英语和日语。好吧,在升级到 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

storyboard中有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文件的东西吗?没看懂……

我可以直接问脚本的创建者,但我认为在这里发布问题会更好。我是这样的情人:)

【问题讨论】:

    标签: bash localization ios7 storyboard xcode5


    【解决方案1】:

    我使用与您相同的脚本,并且遇到与您相同的问题。然后我来自AppliedIS的foundthesearticles,详细介绍了他们的I18n和L10n的过程。他们使用了这个脚本的更新版本,看起来更健壮一些。

    他们还有一个脚本,用于从 NSLocalizedString 语句中提取密钥,并为每个语言环境生成 Localizable.strings。此脚本在生成新条目时使用注释作为值,非常巧妙。

    我现在已经切换到这些,而且它看起来更快(可能只是我;ooh, new == faster),输出更多(非常适合调试),并且在没有Run script only when installing 的情况下也可以工作。

    看看吧! (我与他们没有任何关系,只是一个快乐的用户)

    【讨论】:

    • 谢谢,这似乎是一个很棒的脚本!
    【解决方案2】:

    我认为这是解决方案:

    转到xx.xcodeproj->目标->构建阶段->运行脚本->勾选“仅在安装时运行脚本”

    我不知道如何,为什么但这似乎解决了问题...我想是因为脚本在安装在 ios 模拟器上时运行,所以当我构建时,它找不到 xx.storyboard...

    仍然欢迎任何其他答案。这个我还是不能满足,因为这个解决方案没有保证。

    【讨论】:

      【解决方案3】:

      我相信本地化只发生在应用安装过程中。因此,由于脚本处理本地化资源,因此您的解决方法完全有理由起作用。请注意,本地化中的许多内容都发生了变化,值得查看位于 Apple 开发者网站上的链接 internationalization guide。该链接包含提供进一步解释的特定视频和编程主题。一些值得考虑的事情是,如果您只打算使用单个视图控制器,则应该使用 Autolayout。这将确保您的翻译在每种语言中的大小正确。

      【讨论】:

      • 谢谢。我稍后会重新考虑。对不起,我目前正忙于这个 iOS 项目,没有太多时间在 SO...
      猜你喜欢
      • 2015-06-13
      • 2011-12-07
      • 2012-08-06
      • 2013-11-30
      • 2015-12-10
      • 2014-03-21
      • 2011-11-23
      • 2017-10-27
      • 1970-01-01
      相关资源
      最近更新 更多