#!/bin/sh
# Auto Create Locale Strings Script
# cls.sh
# Find .storyboard file inside project folder
for storyboardPath in `find . -name "*.storyboard" -print`
do
# Get storyboard file name
storyboardFile=$(basename "$storyboardPath")
# Get Base strings file path
baseStringsPath=$(echo "$storyboardPath" | sed 's/storyboard/strings/g')
# Get New Base strings file path
newBaseStringsPath=$(echo "$storyboardPath" | sed 's/\.storyboard/_new\.strings/g')
# Get strings file name
stringsFile=$(basename "$baseStringsPath")
#echo $stringsFile
echo Create $newBaseStringsPath from $storyboardFile
ibtool --export-strings-file $newBaseStringsPath $storyboardPath
# Convert UTF-16 to UTF-8
iconv -f UTF-16 -t UTF-8 $newBaseStringsPath > $baseStringsPath
rm $newBaseStringsPath
# Get all locale strings file path
for localeStringsPath in `find . -name "$stringsFile" -print`
do
if [ $baseStringsPath != $localeStringsPath ]
then
oldLocaleStringsPath=$(echo "$localeStringsPath" | sed 's/\.strings/_old\.strings/g')
cp $localeStringsPath $oldLocaleStringsPath
echo 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
#!/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 . -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 . -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
Shell Script Invocation Error
find: ./Project/Base.lproj/MainStoryboard_iPhone.strings: No such file or directory
./Project/Base.lproj/MainStoryboard_iPhone.storyboard file not modified.
Shell Script Invocation Error
find: ./Project/Base.lproj/MainStoryboard_iPad.strings: No such file or directory
./Project/Base.lproj/MainStoryboard_iPad.storyboard file not modified.
Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure
Well, you can just run "touch ./Project/Base.lproj/MainStoryboard_iPad.strings", this is the simplest way, or you can modify script beforeThank you for this all. I got it to work. But i got 3 errors, when your script is running:
Code:Shell Script Invocation Error find: ./Project/Base.lproj/MainStoryboard_iPhone.strings: No such file or directory ./Project/Base.lproj/MainStoryboard_iPhone.storyboard file not modified. Shell Script Invocation Error find: ./Project/Base.lproj/MainStoryboard_iPad.strings: No such file or directory ./Project/Base.lproj/MainStoryboard_iPad.storyboard file not modified. Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure
How can i solve this?
Check en.lproj folder, delete them if you find any storyboard files, you only need storyboard files in Base.lproj folder.Sorry, but i tried all these points now 3x times and execute my app, it works very well if i switch and run to a foreign language, but if i switch back to english - all my changes in storyboard and for my .strings files will be ignored. instead of that it represents me an old version of my storyboard (with no new changes and so on... - i don't know where xcode get the old storyboard informations?)
I really don't understand what xcode is doing. Do you have any idea, whats going on?
For the foreign language everything works fine.
If you use script what I provide, you don't need to follow steps, script will create storyboard.strings file in Base.lproj and copy and merge them to other lproj folder.
If you still got same error, just copy strings file to Base.lproj folder.
If you use script what I provide, you don't need to follow steps, script will create storyboard.strings file in Base.lproj and copy and merge them to other lproj folder.
If you still got same error, just copy strings file to Base.lproj folder.
Sorry🙂 I am not sure at the moment as it was long time ago🙁You mean the script will do everything from Step #1-9? Or from Step #4-9?
I don't know why it will happen because my script didn't find strings file in Bse.lproj."find: ./Pandora/Base.lproj/MainStoryboard.strings: No such file or directory"
#!/bin/sh
# Update storyboard string files
#
# by 2013 André Pinto andredsp@gmail.com
# based on https://forums.macrumors.com/threads/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