【问题标题】:Localized Storyboards with Base.lproj带有 Base.lproj 的本地化故事板
【发布时间】:2012-09-26 11:42:57
【问题描述】:

在使用 iOS 6 和新的本地化版本时,更新本地化故事板的 .strings 文件的最佳方式是什么?当我切换到新的 Base.lproj 机制时,我的项目很好地创建了字符串文件,但它不会即时更新 .strings 文件。

谢谢!
-f

【问题讨论】:

    标签: ios localization storyboard ios6


    【解决方案1】:

    来自Apple的“国际化和本地化指南”,在这一切的底部:

    在您的项目类型的 Base.lproj 目录中

    ibtool MainStoryboard.storyboard --generate-strings-file NewStuff.strings
    

    然后从NewStuff.strings 合并到您的Storyboard.strings 文件并翻译。

    编辑链接: https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/MaintaingYourOwnStringsFiles/MaintaingYourOwnStringsFiles.html#//apple_ref/doc/uid/10000171i-CH19-SW22

    【讨论】:

    • 该链接指向已停用的文档。不容易看到相关信息现在在哪里。
    【解决方案2】:

    将下面的脚本添加到“构建阶段”->“运行脚本”

    #!/bin/sh
    # cls.sh - script to  Create Locale Strings auto
    
    storyboardExt=".storyboard"
    stringsExt=".strings"
    newStringsExt=".strings.new"
    oldStringsExt=".strings.old"
    localeDirExt=".lproj"
    
    # Find storyboard file full path inside project folder
    for storyboardPath in `find ${SRCROOT} -name "*$storyboardExt" -print`
    do
        # Get Base strings file full path
        baseStringsPath=$(echo "$storyboardPath" | sed "s/$storyboardExt/$stringsExt/")
    
        # Create strings file only when storyboard file newer
        if find $storyboardPath -prune -newer $baseStringsPath -print | grep -q .; then
            # Get storyboard file name and folder 
            storyboardFile=$(basename "$storyboardPath")
            storyboardDir=$(dirname "$storyboardPath")
    
            # Get New Base strings file full path and strings file name
            newBaseStringsPath=$(echo "$storyboardPath" | sed "s/$storyboardExt/$newStringsExt/")
            stringsFile=$(basename "$baseStringsPath")
            ibtool --export-strings-file $newBaseStringsPath $storyboardPath
            iconv -f UTF-16 -t UTF-8 $newBaseStringsPath > $baseStringsPath
            rm $newBaseStringsPath
    
            # Get all locale strings folder 
            for localeStringsDir in `find ${SRCROOT} -name "*$localeDirExt" -print`
            do
                # Skip Base strings folder
                if [ $localeStringsDir != $storyboardDir ]; then
                    localeStringsPath=$localeStringsDir/$stringsFile
    
                    # Just copy base strings file on first time
                    if [ ! -e $localeStringsPath ]; then
                        cp $baseStringsPath $localeStringsPath
                    else
                        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
                fi
            done
        else
            echo "$storyboardPath file not modified."
        fi
    done
    

    【讨论】:

    • 谢谢!这似乎与包含空格的路径有关。从构建阶段运行该脚本时,我不断收到“无文件或目录”错误,并且输出表明它在“Macintosh”和“HD”之间的空间中断。
    • 只需将 quote(") 放到 cls.sh 中的损坏路径中,例如 "${SRCROOT}"
    猜你喜欢
    • 2018-08-17
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    相关资源
    最近更新 更多