0

sorry to make another bother. I'm implement an app, with localization of English and Japanese in xcode 5, using the script file created by André Pinto, based on SIngle Storyboard for multiple languages. Well, before upgrade to xcode 5 (xcode 4.6, I mean), things work properly. But since xcode 5, this error occurs when run the script file:

<?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

In the storyboard, there are 2 sub-files: xx.storyboard(Base) and xx.storyboard(Japanese)

In the first build, no error occur. Everything went fine. App localize so good.

In the second build, I made somechange in storyboard (add some new feature), then error occur. Also, the xx.storyboard(Japanese) become blank, and this is weird. I put lots of effort translate those things, and now I have to do it again...

I think there's some problem with the script, the strings.new and strings.old...

Here's the script:

#!/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 and InfoPlist.strings are still good.

Anyone has experience with this kind of things help me please... Is that something with xcode, or script file or xx.strings file? I don't get it...

I may ask it directly the script's creator, but I think post the question here will be better. I'm a SO lover :)

Eddie
  • 1,903
  • 2
  • 21
  • 46

3 Answers3

1

I think this is the solution:

go to xx.xcodeproj-> Target-> Build phases-> Run Script-> Tick on "Run script only when installing"

I don't know how, why but this seems to solve the problem... I think because the script run when install on ios simulator, so when I build, it can't find the xx.storyboard...

Any other answers are still welcome. I still can't satisfy with this one, because there's no guarantee with this solution.

Eddie
  • 1,903
  • 2
  • 21
  • 46
1

I believe localization only occurs during the install of an app. Therefore your workaround has every reason to work since the script deals with localizing resources. Please note that many things in localization have changed and it would be worthwhile to review the linked internationalization guide located on the Apple developer website. The link contains specific videos and programming topics that provider further explanations. Some things worth considering is that you should use Autolayout if you only plan on using a single view controller. This will ensure your translations size correctly in each language.

Tommie C.
  • 12,895
  • 5
  • 82
  • 100
  • Thanks. I'll reconsider it later. I'm sorry, i'm currently busy with this iOS project, don't have much time derping on SO... – Eddie Nov 19 '13 at 06:13
1

I was using same script as you, and had the same issues as you. Then I found these articles from AppliedIS, detailing their process of I18n and L10n. They used an updated version of this script that seems to be slightly more robust.

They also have a script for extracting keys from NSLocalizedString statements and generate Localizable.strings for every locale as well. This script uses the comment as the value when generating the new entries, which is quite clever.

I have switched to these now, and it seems faster (that might be just me; ooh, new == faster), has more output (nice for debugging) and it also works without the Run script only when installing.

Check it out! (I'm not associated with them in any way, just a happy user)

Paaske
  • 4,345
  • 1
  • 21
  • 33