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 scripts lets you manage your Koha templates translations. |
30 |
|
31 |
Usage: |
32 |
$scriptname --list|-l [--all|-a] |
33 |
$scriptname --install|-i language_code |
34 |
$scriptname --update|-u language_code |
35 |
$scriptname --remove|-r language_code |
36 |
$scriptname -h |
37 |
|
38 |
-l | --list List the installed or available (combined with -a) |
39 |
language translations |
40 |
-a | --available Used in conjunction with -l to show all languages |
41 |
-i | --install Install the specified language translations |
42 |
-u | --update Update the specified language translations |
43 |
-r | --remove Remove the specified language translations |
44 |
-h | --help Display this help message |
45 |
|
46 |
EOF |
47 |
} |
48 |
|
49 |
die() { |
50 |
echo "$@" 1>&2 |
51 |
exit 1 |
52 |
} |
53 |
|
54 |
list() { |
55 |
all=$1 |
56 |
if [ "$all" != "" ]; then |
57 |
print_available |
58 |
else |
59 |
print_installed |
60 |
fi |
61 |
} |
62 |
|
63 |
print_available() |
64 |
{ |
65 |
for i in $(ls $PO_DIR | grep opac) |
66 |
do |
67 |
echo `basename $i -i-opac-t-prog-v-3006000.po` |
68 |
done |
69 |
} |
70 |
|
71 |
print_installed() |
72 |
{ |
73 |
for i in $(ls $KOHA_INSTALL_DIR/opac/htdocs/opac-tmpl/prog/ | grep -v -e images -e itemtypeimg) |
74 |
do |
75 |
echo $i |
76 |
done |
77 |
} |
78 |
|
79 |
install_lang() |
80 |
{ |
81 |
lang=$1 |
82 |
|
83 |
if [ "$lang" != "" ]; then |
84 |
|
85 |
if [ "$lang" = "en" ]; then |
86 |
die "Error: the default language (en) is already installed." |
87 |
fi |
88 |
|
89 |
if print_available | grep -q $lang; then |
90 |
if print_installed | grep -q $lang; then |
91 |
die "Error: the selected language is already installed. Try --update if you want to re-install it." |
92 |
else |
93 |
env PERL5LIB="$KOHA_LIB_DIR:$TRANSLATE_DIR" KOHA_CONF="$KOHA_CONF_FILE"\ |
94 |
$PERL_CMD $TRANSLATE_DIR/translate install $lang |
95 |
fi |
96 |
else |
97 |
die "Error: the selected language is not currently available." |
98 |
fi |
99 |
|
100 |
else |
101 |
die "Error: no language code supplied." |
102 |
fi |
103 |
} |
104 |
|
105 |
update_lang() |
106 |
{ |
107 |
lang=$1 |
108 |
|
109 |
if [ "$lang" != "" ]; then |
110 |
|
111 |
if [ "$lang" = "en" ]; then |
112 |
die "Error: the default language (en) cannot be updated." |
113 |
fi |
114 |
|
115 |
if print_installed | grep -q $lang; then |
116 |
env PERL5LIB="$KOHA_LIB_DIR:$TRANSLATE_DIR" KOHA_CONF="$KOHA_CONF_FILE"\ |
117 |
$PERL_CMD $TRANSLATE_DIR/translate update $lang |
118 |
else |
119 |
die "Error: the selected language is not currently installed. Try --install." |
120 |
fi |
121 |
else |
122 |
die "Error: no language code supplied." |
123 |
fi |
124 |
} |
125 |
|
126 |
remove_lang() |
127 |
{ |
128 |
lang=$1 |
129 |
|
130 |
if [ "$lang" != "" ]; then |
131 |
|
132 |
if [ "$lang" = "en" ]; then |
133 |
die "Error: the default language (en) cannot be removed." |
134 |
fi |
135 |
|
136 |
if print_installed | grep -q $lang; then |
137 |
rm -rf $KOHA_INSTALL_DIR/opac/htdocs/opac-tmpl/prog/$lang |
138 |
rm -rf $KOHA_INSTALL_DIR/opac/htdocs/opac-tmpl/ccsr/$lang |
139 |
rm -rf $KOHA_INSTALL_DIR/intranet/htdocs/intranet-tmpl/prog/$lang |
140 |
else |
141 |
die "Error: the selected language is not already installed." |
142 |
fi |
143 |
else |
144 |
die "Error: no language code supplied." |
145 |
fi |
146 |
} |
147 |
|
148 |
# Global PATH variables |
149 |
KOHA_INSTALL_DIR="/usr/share/koha" |
150 |
KOHA_LIB_DIR="/usr/share/koha/lib" |
151 |
KOHA_CONF_FILE="/etc/koha/koha-conf-site.xml.in" |
152 |
TRANSLATE_DIR="$KOHA_INSTALL_DIR/misc/translator" |
153 |
PO_DIR="$TRANSLATE_DIR/po" |
154 |
PERL_CMD=`which perl` |
155 |
# Control variables |
156 |
list_all="" |
157 |
|
158 |
# Read parameters |
159 |
while true ; do |
160 |
case "$1" in |
161 |
-h|--help) |
162 |
op="help" |
163 |
break ;; |
164 |
-i|--install) |
165 |
op="install" |
166 |
language="$2" |
167 |
shift 2 ;; |
168 |
-u|--update) |
169 |
op="update" |
170 |
language="$2" |
171 |
shift 2 ;; |
172 |
-r|--remove) |
173 |
op="remove" |
174 |
language="$2" |
175 |
shift 2 ;; |
176 |
-l|--list) |
177 |
op="list" |
178 |
shift ;; |
179 |
-a|--available) |
180 |
list_all=1 |
181 |
shift ;; |
182 |
*) |
183 |
break ;; |
184 |
esac |
185 |
done |
186 |
|
187 |
# Process the requested actions |
188 |
case $op in |
189 |
"help") |
190 |
usage ;; |
191 |
"list") |
192 |
list $list_all ;; |
193 |
"install") |
194 |
install_lang $language ;; |
195 |
"update") |
196 |
update_lang $language ;; |
197 |
"remove") |
198 |
remove_lang $language ;; |
199 |
*) |
200 |
usage |
201 |
die "Error: wrong parameters..." ;; |
202 |
esac |
203 |
|
204 |
exit 0 |
205 |
|