#!/bin/sh # # TranslateNib.sh # # This tools helps creating localized nib files, # using nibtool. # # Copyright Stephane Corthesy 2001-2003, stephane@sente.ch # # Mar 7 2002: v1, initial public release # Jul 12 2002: v2, corrected CVS problem # Jan 3 2003: v3, adapted for Dec 2002 Dev Tools; added Subversion support # usage ( ) { echo "Usage: `basename $0` operation language file" echo " operation must be 'start' or 'end'" echo " language must be English, French, Spanish, ..." echo " file is the original nib file" echo " (Output directory must be writable)" } if [ $# -ne 3 ] ; then \ usage ; \ exit 1 fi operation="$1" editor="/Applications/TextEdit.app" if [ "$operation" != "start" -a "$operation" != "end" ] ; then \ usage ; \ exit 1 fi # Let's remove .nib/ suffix, if any filename=`basename "$3" .nib` inputDir=`dirname "$3"` inputFile="$inputDir/$filename.nib" # Now we check that source nib exists if [ ! -d "$inputFile" ] ; then \ echo "No such file "$inputFile ; \ exit 1 fi language="$2" outputDir="$inputDir/../$language.lproj" tempStringFile="$outputDir/___$filename.strings" outputFile="$outputDir/$filename.nib" if [ ! -d "$outputDir" ] ; then \ mkdir "$outputDir" fi # If user already translated nib in the past, we update it: # We use old translation strings + layout, merged with # new strings+elements if [ "$operation" = "start" ] ; then { if [ -d "$outputFile" ] ; then rm -rf "$tempStringFile" ; \ nibtool --previous "$outputFile" \ --localizable-strings \ --incremental "$outputFile" "$inputFile"\ > "$tempStringFile" ; \ open "$inputFile" else rm -rf "$tempStringFile" ; \ nibtool --localizable-strings "$inputFile" \ > "$tempStringFile" ; \ open "$inputFile" fi open -a "$editor" "$tempStringFile" } else { # Verify that .strings file format is correct pl < "$tempStringFile" > /dev/null if [ -d "$outputFile" ] ; then { # Let's preserve CVS/Subversion information, as nibtool doesn't... if [ -d "$outputFile/CVS" ] ; then cp -pR "$outputFile/CVS" "$outputFile/../CVS.tmp" fi if [ -d "$outputFile/.svn" ] ; then cp -pR "$outputFile/.svn" "$outputFile/../.svn.tmp" fi nibtool --dictionary "$tempStringFile" \ --Write "$outputFile" \ --incremental "$outputFile" \ "$inputFile" ; \ if [ -d "$outputFile/../CVS.tmp" ] ; then mv "$outputFile/../CVS.tmp" "$outputFile/CVS" fi if [ -d "$outputFile/../.svn.tmp" ] ; then mv "$outputFile/../.svn.tmp" "$outputFile/.svn" fi } else nibtool --dictionary "$tempStringFile" \ --write "$outputFile" \ "$inputFile" fi rm -rf "$tempStringFile" open "$outputFile" } fi # If file has only 2 bytes, it is empty #if [ -z `cut -b "3,4" < "$tempStringFile"` ] ; then \ # echo "Nothing to translate" # rm -rf "$tempStringFile" ; \ #else # open "$inputFile" # open -a "$editor" "$tempStringFile" #fi exit 0