Line 0
Link Here
|
0 |
- |
1 |
#!/bin/sh |
|
|
2 |
# |
3 |
# koha-translate -- Manage Koha translations. |
4 |
# Copyright 2013 Tomás Cohen Arazi |
5 |
# Universidad Nacional de Córdoba |
6 |
# |
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. |
11 |
# |
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. |
16 |
# |
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/>. |
19 |
|
20 |
|
21 |
set -e |
22 |
|
23 |
usage() |
24 |
{ |
25 |
local scriptname=$(basename $0) |
26 |
cat <<EOF |
27 |
$scriptname |
28 |
|
29 |
This script lets you manage your Koha templates translations. |
30 |
|
31 |
Usage: |
32 |
$scriptname --list|-l [--all|-a] |
33 |
$scriptname --check|-c language_code |
34 |
$scriptname --install|-i language_code |
35 |
$scriptname --update|-u language_code |
36 |
$scriptname --remove|-r language_code |
37 |
$scriptname -h |
38 |
|
39 |
-l | --list List the installed or available (combined with -a) |
40 |
language translations |
41 |
-a | --available Used in conjunction with -l to show all languages |
42 |
-c | --check Check that the language .PO files are present |
43 |
-i | --install Install the specified language translations |
44 |
-u | --update Update the specified language translations |
45 |
-r | --remove Remove the specified language translations |
46 |
-h | --help Display this help message |
47 |
|
48 |
EOF |
49 |
} |
50 |
|
51 |
die() { |
52 |
echo "$@" 1>&2 |
53 |
exit 1 |
54 |
} |
55 |
|
56 |
list() { |
57 |
all=$1 |
58 |
if [ "$all" != "" ]; then |
59 |
print_available |
60 |
else |
61 |
print_installed |
62 |
fi |
63 |
} |
64 |
|
65 |
print_available() |
66 |
{ |
67 |
# Loop over only one opac theme |
68 |
for i in $( ls $PO_DIR | grep opac-t-prog ) |
69 |
do |
70 |
echo `basename $i -i-opac-t-prog-v-3006000.po` |
71 |
done |
72 |
} |
73 |
|
74 |
print_installed() |
75 |
{ |
76 |
ls $KOHA_INSTALL_DIR/opac/htdocs/opac-tmpl/prog/ | \ |
77 |
grep -v -e images -e itemtypeimg |
78 |
} |
79 |
|
80 |
install_lang() |
81 |
{ |
82 |
lang=$1 |
83 |
|
84 |
if [ "$lang" != "" ]; then |
85 |
|
86 |
if [ "$lang" = "en" ]; then |
87 |
die "Error: the default language (en) is already installed." |
88 |
fi |
89 |
|
90 |
if print_available | grep -q $lang; then |
91 |
if print_installed | grep -q $lang; then |
92 |
die "Error: the selected language is already installed. Try --update if you want to re-install it." |
93 |
else |
94 |
# Check po files are present |
95 |
check_lang_po_files $lang |
96 |
env PERL5LIB="$KOHA_LIB_DIR:$TRANSLATE_DIR" KOHA_CONF="$KOHA_CONF_FILE"\ |
97 |
$PERL_CMD $TRANSLATE_DIR/translate install $lang |
98 |
fi |
99 |
else |
100 |
die "Error: the selected language is not currently available." |
101 |
fi |
102 |
|
103 |
else |
104 |
die "Error: no language code supplied." |
105 |
fi |
106 |
} |
107 |
|
108 |
update_lang() |
109 |
{ |
110 |
lang=$1 |
111 |
|
112 |
if [ "$lang" != "" ]; then |
113 |
|
114 |
if [ "$lang" = "en" ]; then |
115 |
die "Error: the default language (en) cannot be updated." |
116 |
fi |
117 |
|
118 |
if print_installed | grep -q $lang; then |
119 |
# Check po files are present |
120 |
check_lang_po_files $lang |
121 |
remove_lang $lang |
122 |
install_lang $lang |
123 |
else |
124 |
die "Error: the selected language is not currently installed. Try --install." |
125 |
fi |
126 |
else |
127 |
die "Error: no language code supplied." |
128 |
fi |
129 |
} |
130 |
|
131 |
remove_lang() |
132 |
{ |
133 |
lang=$1 |
134 |
|
135 |
if [ "$lang" != "" ]; then |
136 |
|
137 |
if [ "$lang" = "en" ]; then |
138 |
die "Error: the default language (en) cannot be removed." |
139 |
fi |
140 |
|
141 |
if print_installed | grep -q $lang; then |
142 |
rm -rf $KOHA_INSTALL_DIR/opac/htdocs/opac-tmpl/prog/$lang |
143 |
rm -rf $KOHA_INSTALL_DIR/opac/htdocs/opac-tmpl/ccsr/$lang |
144 |
rm -rf $KOHA_INSTALL_DIR/intranet/htdocs/intranet-tmpl/prog/$lang |
145 |
else |
146 |
die "Error: the selected language is not already installed." |
147 |
fi |
148 |
else |
149 |
die "Error: no language code supplied." |
150 |
fi |
151 |
} |
152 |
|
153 |
check_lang_po_files() |
154 |
{ |
155 |
lang=$1 |
156 |
po_files="$PO_DIR/$lang-i-opac-t-prog-v-3006000.po |
157 |
$PO_DIR/$lang-opac-ccsr.po |
158 |
$PO_DIR/$lang-i-staff-t-prog-v-3006000.po |
159 |
$PO_DIR/$lang-pref.po" |
160 |
|
161 |
if [ "$lang" != "" ]; then |
162 |
|
163 |
for po_file in $po_files |
164 |
do |
165 |
if [ ! -f $po_file ]; then |
166 |
die "Error: $po_file not found." |
167 |
fi |
168 |
done |
169 |
else |
170 |
die "Error: no language code supplied." |
171 |
fi |
172 |
} |
173 |
|
174 |
set_action() |
175 |
{ |
176 |
if [ "$op" = "" ]; then |
177 |
op=$1 |
178 |
else |
179 |
die "Error: only one action can be specified." |
180 |
fi |
181 |
} |
182 |
|
183 |
# Global PATH variables |
184 |
KOHA_INSTALL_DIR="/usr/share/koha" |
185 |
KOHA_LIB_DIR="/usr/share/koha/lib" |
186 |
KOHA_CONF_FILE="/etc/koha/koha-conf-site.xml.in" |
187 |
TRANSLATE_DIR="$KOHA_INSTALL_DIR/misc/translator" |
188 |
PO_DIR="$TRANSLATE_DIR/po" |
189 |
PERL_CMD=`which perl` |
190 |
|
191 |
# Control variables |
192 |
list_all="" |
193 |
op="" |
194 |
language="" |
195 |
|
196 |
# We accept at most 2 parameters |
197 |
[ $# -ge 1 ] && [ $# -le 3 ] || ( usage ; die "Error: wrong parameters" ) |
198 |
|
199 |
# Read parameters |
200 |
while [ $# -gt 0 ] |
201 |
do |
202 |
case "$1" in |
203 |
-h|--help) |
204 |
op="help" |
205 |
break ;; |
206 |
-c|--check) |
207 |
set_action "check" |
208 |
shift ;; |
209 |
-i|--install) |
210 |
set_action "install" |
211 |
shift ;; |
212 |
-u|--update) |
213 |
set_action "update" |
214 |
shift ;; |
215 |
-r|--remove) |
216 |
set_action "remove" |
217 |
shift ;; |
218 |
-l|--list) |
219 |
set_action "list" |
220 |
shift ;; |
221 |
-a|--available) |
222 |
list_all=1 |
223 |
shift ;; |
224 |
-*) |
225 |
usage |
226 |
die "Error: unknown parameter $1." ;; |
227 |
*) |
228 |
language=$1 |
229 |
shift ;; |
230 |
esac |
231 |
done |
232 |
|
233 |
# Process the requested actions |
234 |
case $op in |
235 |
"help") |
236 |
usage ;; |
237 |
"list") |
238 |
list $list_all ;; |
239 |
"install") |
240 |
install_lang $language ;; |
241 |
"update") |
242 |
update_lang $language ;; |
243 |
"remove") |
244 |
remove_lang $language ;; |
245 |
"check") |
246 |
check_lang_po_files $language ;; |
247 |
*) |
248 |
usage |
249 |
die "Error: wrong parameters..." ;; |
250 |
esac |
251 |
|
252 |
exit 0 |