1 |
6daefa8c
|
Petr Lukašík
|
#!/bin/bash
|
2 |
|
|
# This script will synchronize language file with the master
|
3 |
|
|
# english translation using diff(1) utility.
|
4 |
|
|
# It doesn't translate strings, only inserts english versions
|
5 |
|
|
# to proper positions and deletes removed. And it doesn't
|
6 |
|
|
# synchronize commented lines.
|
7 |
|
|
# You need to have GNU ed and diff installed in $PATH.
|
8 |
|
|
#
|
9 |
|
|
# Usage: synch <language>
|
10 |
|
|
#
|
11 |
|
|
# <language> is the filename without the .php extension
|
12 |
|
|
#
|
13 |
|
|
# BTW, diff should create better ed scripts than previous
|
14 |
|
|
# version of synch (that one with awk code). If it will not,
|
15 |
|
|
# be frightened about patching Linux kernel sources ;-)
|
16 |
|
|
|
17 |
|
|
if [ -z $1 ] ; then
|
18 |
|
|
echo "You must tell me which language I should synchronize."
|
19 |
|
|
echo -e "for example: \n\t$0 polish"
|
20 |
|
|
exit
|
21 |
|
|
fi
|
22 |
|
|
|
23 |
|
|
if [ ! -f $1.php ] ; then
|
24 |
|
|
echo "Sorry, I cannot find $1.php"
|
25 |
|
|
exit
|
26 |
|
|
fi
|
27 |
|
|
|
28 |
|
|
echo "Making backup of $1.php"
|
29 |
|
|
cp $1.php $1.php.old
|
30 |
|
|
|
31 |
|
|
# Find variables names ( "$lang['strfoo']" part )
|
32 |
|
|
cat english.php | awk -F"=" '{print $1}' > english.tmp
|
33 |
|
|
cat $1.php | awk -F"=" '{print $1}' > $1.tmp
|
34 |
|
|
|
35 |
|
|
# diff variable names and create ed script
|
36 |
|
|
diff --ignore-case --ignore-all-space --ignore-blank-lines \
|
37 |
|
|
--ignore-matching-lines="*" \
|
38 |
|
|
--ignore-matching-lines="[^:]//" \
|
39 |
|
|
--ed \
|
40 |
|
|
$1.tmp english.tmp > diff.ed
|
41 |
|
|
|
42 |
|
|
# No more need for .tmp files
|
43 |
|
|
rm *.tmp
|
44 |
|
|
|
45 |
|
|
# Add english values and ed destination file
|
46 |
|
|
cat diff.ed | awk '
|
47 |
|
|
function grep_n(what, where, n, ln) {
|
48 |
|
|
# Returns line with searched text
|
49 |
|
|
|
50 |
|
|
while ( (getline line < where ) > 0 ) {
|
51 |
|
|
if (index(line, what)>0) {
|
52 |
|
|
gsub("^\t","",what);
|
53 |
|
|
split(line,a,"=");
|
54 |
|
|
print what" = "a[2];
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
close(where);
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
BEGIN { FS="=" }
|
61 |
|
|
|
62 |
|
|
/\$lang/{ grep_n($1, "english.php") ;
|
63 |
|
|
next; }
|
64 |
|
|
|
65 |
|
|
{ print }
|
66 |
|
|
END { print "w" }' \
|
67 |
|
|
| ed $1.php
|
68 |
|
|
|
69 |
|
|
# Clean temporary files
|
70 |
|
|
rm diff.ed
|