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
25 # include helper functions
26 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
27 .
"/usr/share/koha/bin/koha-functions.sh"
29 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
35 local scriptname
=$
(basename $0)
40 This script lets you manage your Koha templates translations.
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]
50 -l | --list List the installed or available (combined with -a)
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
68 if [ "$all" != "" ]; then
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` | \
86 ( ls -1 $KOHA_HOME/$OPAC_TMPL/bootstrap
/ ; \
87 ls -1 $KOHA_HOME/$OPAC_TMPL/prog
/ 2> /dev
/null
) | \
89 grep -v -e images
-e itemtypeimg
-x -e en
-e css
-e js
-e less -e lib
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."
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
118 die
"Error: the selected language is not currently available."
122 die
"Error: no language code supplied."
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
142 die
"Error: the selected language is not currently installed. Try --install."
145 die
"Error: no language code supplied."
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
163 die
"Error: the selected language is not installed."
166 die
"Error: no language code supplied."
170 check_lang_po_files
()
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-help.po
180 $PO_DIR/$lang-staff-prog.po"
182 if [ "$lang" != "" ]; then
184 for po_file
in $po_files; do
185 if [ ! -f $po_file ]; then
186 die
"Error: $po_file not found."
190 die
"Error: no language code supplied."
196 if [ "$op" = "" ]; then
199 die
"Error: only one action can be specified."
205 if is_instance
$1; then
208 die
"Error: Invalid instance name $1"
214 if [ "$dev" != "" ]; then
215 KOHA_CONF
=/etc
/koha
/sites
/$dev/koha-conf.xml
216 elif [ -z $KOHA_CONF ]; then
217 KOHA_CONF
=/etc
/koha
/koha-conf-site.xml.
in
221 init_template_paths
()
224 if [ "$dev" = "" ]; then
225 OPAC_TMPL
=opac
/htdocs
/opac-tmpl
226 INTRANET_TMPL
=intranet
/htdocs
/intranet-tmpl
228 OPAC_TMPL
=koha-tmpl
/opac-tmpl
229 INTRANET_TMPL
=koha-tmpl
/intranet-tmpl
231 TRANSLATE_DIR
="$KOHA_HOME/misc/translator"
232 PO_DIR
="$TRANSLATE_DIR/po"
242 # We accept at most 4 parameters
243 [ $# -ge 1 ] && [ $# -le 4 ] ||
( usage
; die
"Error: wrong parameters" )
246 while [ $# -gt 0 ]; do
274 if [ $# -lt 2 ]; then
275 die
"Error: dev parameter without instance"
282 die
"Error: unknown parameter $1." ;;
290 if [ "$dev" != "" ]; then adjust_paths_dev_install
$dev; fi
293 PERL_CMD
=`which perl`
295 # Process the requested actions
302 install_lang
$language ;;
304 update_lang
$language ;;
306 remove_lang
$language ;;
308 check_lang_po_files
$language ;;
311 die
"Error: wrong parameters..." ;;