Bug 24610: Let user switch between 'Pay' and 'Write off' mode
[koha.git] / debian / scripts / koha-translate
blob69936c000e47505dcfe489a5e12264626b2f5745
1 #!/bin/sh
3 # koha-translate -- Manage Koha translations.
4 # Copyright 2013 Tomás Cohen Arazi
5 # Universidad Nacional de Córdoba
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Read configuration variable file if it is present
21 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
23 set -e
25 # include helper functions
26 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
27 . "/usr/share/koha/bin/koha-functions.sh"
28 else
29 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
30 exit 1
33 usage()
35 local scriptname=$(basename $0)
37 cat <<EOF
38 $scriptname
40 This script lets you manage your Koha templates translations.
42 Usage:
43 $scriptname --list|-l [--available|-a] [-d|--dev instance]
44 $scriptname --check|-c language_code] [-d|--dev instance]
45 $scriptname --install|-i language_code] [-d|--dev instance]
46 $scriptname --update|-u language_code] [-d|--dev instance]
47 $scriptname --remove|-r language_code] [-d|--dev instance]
48 $scriptname --help|-h
50 -l | --list List the installed or available (combined with -a)
51 language translations
52 -a | --available Used in conjunction with -l to show all languages
53 -c | --check Check that the language .PO files are present
54 -i | --install Install the specified language translations
55 -u | --update Update the specified language translations
56 -r | --remove Remove the specified language translations
57 -v | --verbose Be more verbose on the translation process
58 -h | --help Display this help message
59 -d | --dev Limit actions to a specific dev instance
61 EOF
64 list()
66 all=$1
68 if [ "$all" != "" ]; then
69 print_available
70 else
71 print_installed
75 print_available()
77 # Loop over only one opac theme
78 for i in $( ls $PO_DIR | grep opac-bootstrap ); do
79 echo `basename $i -opac-bootstrap.po` | \
80 grep -v -x -e en
81 done
84 print_installed()
86 ( ls -1 $KOHA_HOME/$OPAC_TMPL/bootstrap/ ; \
87 ls -1 $KOHA_HOME/$OPAC_TMPL/prog/ 2> /dev/null ) | \
88 sort | uniq | \
89 grep -v -e images -e itemtypeimg -x -e en -e css -e js -e less -e lib
92 install_lang()
94 local lang=$1
95 local translate_opts=""
97 if [ "$verbose" = "yes" ]; then
98 translate_opts="--verbose"
101 if [ "$lang" != "" ]; then
103 if [ "$lang" = "en" ]; then
104 die "Error: the default language (en) is already installed."
107 if print_available | grep -q $lang; then
108 if print_installed | grep -q $lang; then
109 die "Error: the selected language is already installed. Try --update if you want to re-install it."
110 else
111 # Check po files are present
112 check_lang_po_files $lang
113 env PERL5LIB="$PERL5LIB:$TRANSLATE_DIR" \
114 KOHA_CONF="$KOHA_CONF" \
115 $PERL_CMD $TRANSLATE_DIR/translate install $translate_opts $lang
117 else
118 die "Error: the selected language is not currently available."
121 else
122 die "Error: no language code supplied."
126 update_lang()
128 lang=$1
130 if [ "$lang" != "" ]; then
132 if [ "$lang" = "en" ]; then
133 die "Error: the default language (en) cannot be updated."
136 if print_installed | grep -q $lang; then
137 # Check po files are present
138 check_lang_po_files $lang
139 remove_lang $lang
140 install_lang $lang
141 else
142 die "Error: the selected language is not currently installed. Try --install."
144 else
145 die "Error: no language code supplied."
149 remove_lang()
151 lang=$1
153 if [ "$lang" != "" ]; then
155 if [ "$lang" = "en" ]; then
156 die "Error: the default language (en) cannot be removed."
159 if print_installed | grep -q $lang; then
160 rm -rf $KOHA_HOME/$OPAC_TMPL/bootstrap/$lang
161 rm -rf $KOHA_HOME/$INTRANET_TMPL/prog/$lang
162 else
163 die "Error: the selected language is not installed."
165 else
166 die "Error: no language code supplied."
170 check_lang_po_files()
172 lang=$1
174 po_files="$PO_DIR/$lang-marc-MARC21.po
175 $PO_DIR/$lang-marc-NORMARC.po
176 $PO_DIR/$lang-marc-UNIMARC.po
177 $PO_DIR/$lang-opac-bootstrap.po
178 $PO_DIR/$lang-pref.po
179 $PO_DIR/$lang-staff-prog.po"
181 if [ "$lang" != "" ]; then
183 for po_file in $po_files; do
184 if [ ! -f $po_file ]; then
185 die "Error: $po_file not found."
187 done
188 else
189 die "Error: no language code supplied."
193 set_action()
195 if [ "$op" = "" ]; then
196 op=$1
197 else
198 die "Error: only one action can be specified."
202 set_dev()
204 if is_instance $1; then
205 dev=$1
206 else
207 die "Error: Invalid instance name $1"
211 check_koha_conf()
213 if [ "$dev" != "" ]; then
214 KOHA_CONF=/etc/koha/sites/$dev/koha-conf.xml
215 elif [ -z $KOHA_CONF ]; then
216 KOHA_CONF=/etc/koha/koha-conf-site.xml.in
220 init_template_paths()
222 # Template paths
223 if [ "$dev" = "" ]; then
224 OPAC_TMPL=opac/htdocs/opac-tmpl
225 INTRANET_TMPL=intranet/htdocs/intranet-tmpl
226 else
227 OPAC_TMPL=koha-tmpl/opac-tmpl
228 INTRANET_TMPL=koha-tmpl/intranet-tmpl
230 TRANSLATE_DIR="$KOHA_HOME/misc/translator"
231 PO_DIR="$TRANSLATE_DIR/po"
234 flush_cache()
236 if [ "$dev" = "" ]; then
237 koha-foreach --enabled "$KOHA_HOME/bin/clear_cache.pl"
238 else
239 koha-shell $dev -c "$KOHA_HOME/misc/bin/clear_cache.pl"
243 # Control variables
244 list_all=""
245 op=""
246 language=""
247 verbose="no"
248 dev=""
250 # We accept at most 4 parameters
251 [ $# -ge 1 ] && [ $# -le 4 ] || ( usage ; die "Error: wrong parameters" )
253 # Read parameters
254 while [ $# -gt 0 ]; do
256 case "$1" in
257 -h|--help)
258 op="help"
259 break ;;
260 -c|--check)
261 set_action "check"
262 shift ;;
263 -i|--install)
264 set_action "install"
265 shift ;;
266 -u|--update)
267 set_action "update"
268 shift ;;
269 -r|--remove)
270 set_action "remove"
271 shift ;;
272 -l|--list)
273 set_action "list"
274 shift ;;
275 -a|--available)
276 list_all=1
277 shift ;;
278 -v|--verbose)
279 verbose="yes"
280 shift ;;
281 -d|--dev)
282 if [ $# -lt 2 ]; then
283 die "Error: dev parameter without instance"
285 shift
286 set_dev $1
287 shift ;;
289 usage
290 die "Error: unknown parameter $1." ;;
292 language=$1
293 shift ;;
294 esac
296 done
298 if [ "$dev" != "" ]; then adjust_paths_dev_install $dev; fi
299 check_koha_conf
300 init_template_paths
301 PERL_CMD=`which perl`
303 # Process the requested actions
304 case $op in
305 "help")
306 usage ;;
307 "list")
308 list $list_all ;;
309 "install")
310 install_lang $language
311 flush_cache
313 "update")
314 update_lang $language ;;
315 "remove")
316 remove_lang $language
317 flush_cache
319 "check")
320 check_lang_po_files $language ;;
322 usage
323 die "Error: wrong parameters..." ;;
324 esac
326 exit 0