source: trunk/ICeCoffEE/TranslateNib.sh@ 184

Last change on this file since 184 was 109, checked in by Nicholas Riley, 19 years ago

nib translation script, courtesy stephane@…

File size: 2.8 KB
Line 
1#!/bin/sh
2#
3# TranslateNib.sh
4#
5# This tools helps creating localized nib files,
6# using nibtool.
7#
8# Copyright Stephane Corthesy 2001-2003, stephane@sente.ch
9#
10# Mar 7 2002: v1, initial public release
11# Jul 12 2002: v2, corrected CVS problem
12# Jan 3 2003: v3, adapted for Dec 2002 Dev Tools; added Subversion support
13#
14
15usage ( ) {
16 echo "Usage: `basename $0` operation language file"
17 echo " operation must be 'start' or 'end'"
18 echo " language must be English, French, Spanish, ..."
19 echo " file is the original nib file"
20 echo " (Output directory must be writable)"
21}
22
23if [ $# -ne 3 ] ; then \
24 usage ; \
25 exit 1
26fi
27
28operation="$1"
29editor="/Applications/TextEdit.app"
30
31if [ "$operation" != "start" -a "$operation" != "end" ] ; then \
32 usage ; \
33 exit 1
34fi
35
36# Let's remove .nib/ suffix, if any
37filename=`basename "$3" .nib`
38inputDir=`dirname "$3"`
39inputFile="$inputDir/$filename.nib"
40
41# Now we check that source nib exists
42if [ ! -d "$inputFile" ] ; then \
43 echo "No such file "$inputFile ; \
44 exit 1
45fi
46
47language="$2"
48outputDir="$inputDir/../$language.lproj"
49tempStringFile="$outputDir/___$filename.strings"
50outputFile="$outputDir/$filename.nib"
51
52if [ ! -d "$outputDir" ] ; then \
53 mkdir "$outputDir"
54fi
55
56# If user already translated nib in the past, we update it:
57# We use old translation strings + layout, merged with
58# new strings+elements
59
60if [ "$operation" = "start" ] ; then {
61 if [ -d "$outputFile" ] ; then
62 rm -rf "$tempStringFile" ; \
63 nibtool --previous "$outputFile" \
64 --localizable-strings \
65 --incremental "$outputFile" "$inputFile"\
66 > "$tempStringFile" ; \
67 open "$inputFile"
68 else
69 rm -rf "$tempStringFile" ; \
70 nibtool --localizable-strings "$inputFile" \
71 > "$tempStringFile" ; \
72 open "$inputFile"
73 fi
74 open -a "$editor" "$tempStringFile"
75} else {
76 # Verify that .strings file format is correct
77 pl < "$tempStringFile" > /dev/null
78 if [ -d "$outputFile" ] ; then {
79 # Let's preserve CVS/Subversion information, as nibtool doesn't...
80 if [ -d "$outputFile/CVS" ] ; then
81 cp -pR "$outputFile/CVS" "$outputFile/../CVS.tmp"
82 fi
83 if [ -d "$outputFile/.svn" ] ; then
84 cp -pR "$outputFile/.svn" "$outputFile/../.svn.tmp"
85 fi
86 nibtool --dictionary "$tempStringFile" \
87 --Write "$outputFile" \
88 --incremental "$outputFile" \
89 "$inputFile" ; \
90 if [ -d "$outputFile/../CVS.tmp" ] ; then
91 mv "$outputFile/../CVS.tmp" "$outputFile/CVS"
92 fi
93 if [ -d "$outputFile/../.svn.tmp" ] ; then
94 mv "$outputFile/../.svn.tmp" "$outputFile/.svn"
95 fi
96 } else
97 nibtool --dictionary "$tempStringFile" \
98 --write "$outputFile" \
99 "$inputFile"
100 fi
101 rm -rf "$tempStringFile"
102 open "$outputFile"
103} fi
104
105# If file has only 2 bytes, it is empty
106#if [ -z `cut -b "3,4" < "$tempStringFile"` ] ; then \
107# echo "Nothing to translate"
108# rm -rf "$tempStringFile" ; \
109#else
110# open "$inputFile"
111# open -a "$editor" "$tempStringFile"
112#fi
113
114exit 0
Note: See TracBrowser for help on using the repository browser.