Make sure to await close of stream.
[cyberduck.git] / i18n.sh
blobb3b54dafefb03ec7ac8f672d4a851596ee98a905
1 # Copyright (c) 2003 David Kocher. All rights reserved.
2 # http://cyberduck.ch/
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # Bug fixes, suggestions and comments should be sent to:
15 # dkocher@cyberduck.ch
17 #!/bin/bash
19 nibtool="ibtool"
20 convertstrings="ruby convertstrings.rb"
21 base_language="en.lproj"
22 arch="x86_64"
23 tx="/usr/local/bin/tx"
24 extension=".xib"
26 usage() {
27 echo ""
28 echo " Usage: i18n.sh [-l <language>] --status"
29 echo " Usage: i18n.sh [-l <language>] --init"
30 echo " Usage: i18n.sh [-l <language>] [-n <$extension>] [--force] --update"
31 echo " Usage: i18n.sh [-l <language>] --run"
32 echo ""
33 echo "<language> must be Japanese.lproj, French.lproj, Spanish.lproj, ..."
34 echo "<$extension> must be Preferences.$extension, Main.$extension, ..."
35 echo ""
36 echo "Call with no parameters to update all languages and all $extension files"
37 echo ""
40 init() {
41 mkdir -p $language
42 for n in `ls $base_language | grep .$extension | grep -v ~.$extension`; do
44 echo "Copying $n"
45 cp -R $base_language/$n $language/$n
47 done
48 for stringsfile in `ls $base_language | grep .strings`; do
50 echo "Copying $stringsfile"
51 cp -R $base_language/$stringsfile $language/$stringsfile
53 done
54 cp $base_language/License.txt $language/
57 test() {
58 for lproj in `ls . | grep lproj`; do
59 language=$lproj;
60 run;
61 done;
64 run() {
65 echo "Running app using `basename $language .lproj`...";
66 arch -arch $arch ./build/Cyberduck.app/Contents/MacOS/Cyberduck -AppleLanguages "(`basename $language .lproj`)"
69 nib() {
70 #Changes to the .strings has precedence over the NIBs
71 import_strings;
72 #Update the .strings with new values from NIBs
73 export_strings;
76 import_strings() {
77 if($force == true); then
79 # force update
80 echo "*** Updating $nib... (force) in $language..."
81 $nibtool --reference-external-strings-file \
82 --write $language/$nibfile \
83 --import-strings-file $language/$nib.strings \
84 $base_language/$nibfile
86 else
88 # incremental update
89 echo "*** Updating $nib... (incremental) in $language..."
90 $nibtool --write $language/$nibfile \
91 --incremental-file $language/$nibfile \
92 --previous-file $base_language/$nibfile \
93 --import-strings-file $language/$nib.strings \
94 --localize-incremental $base_language/$nibfile
96 fi;
99 export_strings() {
100 echo "*** Updating $nib.strings in $language..."
101 $nibtool --export-strings-file $language/$nib.strings $language/$nibfile
104 export_strings_legacy() {
105 for lproj in `ls . | grep lproj`; do
106 language=$lproj;
107 echo "*** Updating $language Localization...";
108 for nibfile in `ls $language | grep $extension`; do
109 nib=`basename $nibfile $extension`
110 echo "Update $language/$nib.strings.1 from $base_language/$nib.strings"
111 $convertstrings $base_language/$nib.strings $language/$nib.strings > $language/$nib.strings.1
112 done;
113 done;
116 update() {
117 if [ "$language" = "all" ] ; then
119 echo "*** Updating all localizations...";
120 for lproj in `ls . | grep lproj`; do
121 language=$lproj;
122 if [ $language != $base_language ]; then
124 echo "*** Updating $language Localization...";
125 if [ "$nibfile" = "all" ] ; then
126 echo "*** Updating all NIBs...";
127 for nibfile in `ls $language | grep $extension`; do
128 nib=`basename $nibfile $extension`
129 $nibtool --export-strings-file $base_language/$nib.strings $base_language/$nibfile
130 nib;
131 done;
133 if [ "$nibfile" != "all" ] ; then
134 nib=`basename $nibfile $extension`
135 $nibtool --export-strings-file $base_language/$nib.strings $base_language/$nibfile
136 nib;
140 done;
142 else
144 echo "*** Updating $language Localization...";
145 if [ "$nibfile" = "all" ] ; then
146 echo "*** Updating all NIBs...";
147 for nibfile in `ls $language | grep $extension`; do
148 nib=`basename $nibfile $extension`;
149 $nibtool --export-strings-file $base_language/$nib.strings $base_language/$nibfile
150 nib;
151 done;
153 if [ "$nibfile" != "all" ] ; then
155 nib=`basename $nibfile $extension`;
156 $nibtool --export-strings-file $base_language/$nib.strings $base_language/$nibfile
157 nib;
164 tx_push() {
165 echo "*** Updating all localizations...";
166 if [ "$stringsfile" = "all" ] ; then
167 echo "*** Updating all .strings...";
168 for stringsfile in `ls en.lproj | grep .strings`; do
169 strings=`basename $stringsfile .strings`
170 echo "*** Updating $strings.strings...";
171 $tx --traceback set --auto-local -r cyberduck.$strings '<lang>'.lproj/$strings.strings --source-language en --type=STRINGS --execute
172 $tx --traceback push --source --translations --resource=cyberduck.$strings --force --no-interactive --skip
173 done;
175 if [ "$stringsfile" != "all" ] ; then
176 strings=`basename $stringsfile .strings`
177 echo "*** Updating $strings.strings...";
178 $tx --traceback set --auto-local -r cyberduck.$strings '<lang>'.lproj/$strings.strings --source-language en --type=STRINGS --execute
179 $tx --traceback push --source --translations --resource=cyberduck.$strings --force --no-interactive --skip
183 tx_pull() {
184 echo "*** Updating all localizations...";
185 if [ "$stringsfile" = "all" ] ; then
186 echo "*** Updating all .strings...";
187 for stringsfile in `ls en.lproj | grep .strings`; do
188 strings=`basename $stringsfile .strings`
189 echo "*** Updating $strings.strings...";
190 $tx --traceback pull --source --resource=cyberduck.$strings --force
191 done;
193 if [ "$stringsfile" != "all" ] ; then
194 strings=`basename $stringsfile .strings`
195 echo "*** Updating $strings.strings...";
196 $tx --traceback pull --source --resource=cyberduck.$strings --force
200 language="all";
201 nibfile="all";
202 stringsfile="all";
203 force=false;
205 while [ "$1" != "" ] # When there are arguments...
206 do case "$1" in
207 -l | --language)
208 shift;
209 language=$1;
210 echo "Using Language:$language";
211 shift;
213 -n | --nib)
214 shift;
215 nibfile=$1;
216 echo "Using Nib:$nibfile";
217 shift;
219 --strings)
220 shift;
221 stringsfile=$1;
222 echo "Using strings:$stringsfile";
223 shift;
225 --convertstrings)
226 export_strings_legacy;
227 exit 0;
228 echo "*** DONE. ***";
230 -f | --force)
231 force=true;
232 shift;
234 -h | --help)
235 usage;
236 exit 0;
237 echo "*** DONE. ***";
239 -i | --init)
240 echo "Init new localization...";
241 init;
242 echo "*** DONE. ***";
243 exit 0;
245 -u | --update)
246 echo "Updating localization...";
247 update;
248 echo "*** DONE. ***";
249 exit 0;
251 -r | --run)
252 run;
253 echo "*** DONE. ***";
254 exit 0;
256 --arch)
257 shift;
258 arch=$1;
259 echo "Running architecture:$arch";
260 shift;
262 --tx-push)
263 echo "Updating .tx...";
264 tx_push;
265 echo "*** DONE. ***";
266 exit 0;
268 --tx-pull)
269 echo "Updating .tx...";
270 tx_pull;
271 echo "*** DONE. ***";
272 exit 0;
274 --test)
275 test;
276 echo "*** DONE. ***";
277 exit 0;
280 echo "Option [$1] not one of [--update, --init, --tx-push, --tx-pull]"; # Error (!)
281 exit 1
282 ;; # Abort Script Now
283 esac;
284 done;
286 usage;