2012-10-05 85 views
2

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

谢谢!
-f

回答

1

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

enter image description here

#!/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 
+0

从[http://forums.macrumors.com/showthread.php?t=1467446](http://forums.macrumors.com/showthread.php?t=1467446 ) – z33

+0

谢谢!这似乎与包含空格的路径有关。从构建阶段运行该脚本时,我总是收到“无文件或目录”错误,输出表明它在“Macintosh”和“HD”之间的空间中断了。 – flohei

+0

只需将报价(“)放入cls.sh中的损坏路径中,如”$ {SRCROOT}“ – z33

9

从苹果公司的“国际化和本地化指南”,在这一切的底部:

内,您的项目类型的Base.lproj目录

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

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

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

+0

即可将指向已经停用的文档的链接指向不容易看到现在的相关信息。 –