-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddlanguage
executable file
·148 lines (136 loc) · 4.58 KB
/
addlanguage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
# Find ZendTo top directory.
# It's either set in $ZENDTOPREFS, or else it's /opt/zendto, or else
# we can't find it so bail out.
if [ "x$ZENDTOPREFS" != "x" ]; then
ZENDTO=$( echo "$ZENDTOPREFS" | sed -e 's/\/[^\/]*$//; s/\/[^/]*$//;' )
else
ZENDTO=/opt/zendto
fi
if [ "x$ZENDTO" = "/" ] || [ "x$ZENDTO" = "/opt" ] || [ ! -d "$ZENDTO" ]; then
echo "I cannot find the ZendTo directory!"
exit 1
fi
BIN="$ZENDTO/bin"
CONFIG="$ZENDTO/config"
LOCALE="$ZENDTO/config/locale"
###################################################
# Work out the OS name ($OS) and version ($OSVER).
# Taken from my ZendTo installer
###################################################
OS=unknown
OSRELEASE=/etc/redhat-release
if [ -f $OSRELEASE ]; then
if grep -q 'Red *Hat' $OSRELEASE; then
OS=redhat
elif grep -q 'CentOS' $OSRELEASE; then
OS=centos
fi
if [ -x /bin/yum -o -x /usr/bin/yum ]; then
rpm -q --quiet perl || {
shout Just going to install Perl...
yum -y install perl
}
fi
OSVERFULL="$( perl -pe 's/^[^\d]+([\d.]+).*?$/$1/' < $OSRELEASE )"
OSVER="$( echo "$OSVERFULL" | cut -d. -f1 )"
fi
if [ "$OS" = "unknown" ]; then
OSRELEASE=/etc/debian_version
if [ -f $OSRELEASE -a -x /usr/bin/lsb_release ]; then
# Should give me the string "ubuntu" or "debian"
OS="$( lsb_release --id | sed -e 's/^.*:\s*//' | tr '[:upper:]' '[:lower:]' )"
OSVER="$( lsb_release --release | sed -e 's/^.*:\s*\([0-9]*\).*$/\1/' )"
fi
fi
if [ "$OS" = "unknown" ]; then
if [ -x /usr/bin/lsb_release ]; then
# Should give me the string "suse" or similar
OS="$( lsb_release --id | sed -e 's/^.*:\s*//' | tr '[:upper:]' '[:lower:]' )"
OSVER="$( lsb_release --release | sed -e 's/^.*:\s*\([0-9]*\).*$/\1/' )"
# But we need to tell between suse (i.e. sles) and opensuse
if [ "x$OS" = "xsuse" ]; then
OS='sles'
fi
elif [ -f /etc/os-release ]; then
# I can just source that file, but that's dangerous
OSID="$( grep '^ID=' /etc/os-release | head -1 | sed -e 's/#.*$//; s/ *$//; s/^ID="*\([^"]*\)"*/\1/;' )"
if [[ $OSID =~ sles ]]; then
OS='sles'
elif [[ $OSID =~ opensuse ]]; then
OS='opensuse'
elif [[ $OSID =~ debian ]]; then
OS='debian'
fi
OSVER="$( grep '^VERSION_ID=' /etc/os-release | head -1 | sed -e 's/#.*$//; s/ *$//; s/^VERSION_ID="*\([^"]*\)"*/\1/; s/\..*$//;' )"
fi
fi
OS="$(echo "$OS" | tr '[:upper:]' '[:lower:]')" # Lower-case it
###################################################
L="$1"
BAILOUT="$2"
if [ "x$L" = "x" ]; then
echo
echo You need to supply a valid language code on the command-line,
echo such as en_US or fr_FR or similar.
echo "Do not put anything like '.utf-8' on the end,"
echo as everything is done in utf-8 anyway.
echo
if [ "x$OS" = "xredhat" ] || [ "x$OS" = "xcentos" ]; then
echo To see the codes valid on your system, run the command
echo ' locale -a'
echo
fi
exit 1
fi
if echo "$L" | fgrep -q .; then
echo 'Do you *really* need the "." and whatever is after it?'
echo "I'm going to wait for 10 seconds so you can press Ctrl-C"
echo "and try again without it."
sleep 10
echo
fi
echo
if locale -a | grep -q '^'"$L"'$'; then
echo Adding $L as a valid language code.
elif [ "x$OS" = "xubuntu" ] || [ "x$OS" = "xdebian" ]; then
echo Adding the locale for you.
if [ "x$OS" = "xdebian" -a "$OSVER" -ge "9" ]; then
# On Debian 9 we have to __manually edit__ /etc/locale.gen,
# then run locale-gen with no command-line parameters!!!
# WTF ???
if grep -q '^'$L' ' /etc/locale.gen; then
# It's already there, no need to tweak locale-gen
:
else
# Uncomment the line in locale.gen that is the code we want
# Create lots of backups!
sed -i.bak."$L" -e 's/^# *\('"$L"' .*\)$/\1/' /etc/locale.gen
fi
locale-gen
else
locale-gen "$L"
fi
else
echo Sorry, that is not a valid language code on your system.
echo To see the codes valid on your system, run the command
echo ' locale -a'
echo On some operating systems, you may need to install additional
echo software packages to add extra languages.
echo
exit 1
fi
if [ ! -f "$LOCALE/$L/LC_MESSAGES/zendto.po" ]; then
mkdir -p "$LOCALE/$L"
echo And now about to copy the translation source into
echo "$LOCALE/$L/LC_MESSAGES/zendto.po"
echo so you can start adding your own translations.
echo
echo Pausing for 10 secs...
sleep 10
fi
# Only do the makelanguages if they have *not* put a 2nd arg on the command.
# The deb postinst file calls this with NO en the end to save duplicating
# this code.
[ "x$BAILOUT" = "x" ] && "$BIN"/makelanguages
exit 0