-
Notifications
You must be signed in to change notification settings - Fork 383
/
lang2xml
executable file
·80 lines (69 loc) · 1.8 KB
/
lang2xml
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
#!/bin/bash
# This script recodes source lang files into XML Unicode.
# You should add your encodings to this file. You need to have GNU Recode
# installed.
#
# It is important to:
# - fix the delimiters of php code: <?php and ?>
# - convert CRLF -> LF
# - remove all text before first <?php
# - remove all text after last ?>
# - convert "'" -> "'"
# using 'convert.awk'
DESTDIR=./recoded
function prepare () {
RET=""
which recode >/dev/null 2>&1 || \
RET="You must have GNU 'recode' installed to use this Makefile, but I could not find it in your path!\n"
which sed >/dev/null 2>&1 || \
RET="${RET}You must have sed installed to use this Makefile, but I could not find it in your path!\n"
which awk >/dev/null 2>&1 || \
RET="${RET}You must have awk installed to use this Makefile, but I could not find it in your path!\n"
[ ! -z "$RET" ] && echo -ne $RET && exit 1
}
function rec () {
for f in $@
do
[ ! -f $f ] && echo "$f is not a valid file." && continue
DIRNAME=$(dirname $f)
mkdir -p $DIRNAME
echo "Recoding $f..."
NAME=$(basename $f)
cat $f | recode $(grep appcharset $f | cut -d"'" -f 4)..xml | ./convert.awk > $DIRNAME/$DESTDIR/$NAME
chmod 644 $f $DIRNAME/$DESTDIR/$NAME
done
}
function clean () {
echo "Nuking recoded lang files..."
for p in $@
do
rm -fv $p
done
}
prepare
COMMAND=$1
[ -z "$COMMAND" ] && COMMAND="all"
case $COMMAND in
all)
# find all translation files in the source tree
TARGETS=$(ls *.php | grep -v translations.php)
rec $TARGETS
# for f in $TARGETS
# do
# DIRNAME=$(dirname $f)
# rec $f "$DIRNAME/$DESTDIR"
# done
;;
clean)
# find all recoded translation files in the source tree
TARGETS=$(ls ${DESTDIR}/*.php | grep -v translations.php)
clean $TARGETS
;;
*)
rec $@
# for f in $@
# do
# rec $f $DESTDIR
# done
;;
esac