| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (c) 2014 Samuel Degrande |
| 4 |
# |
| 5 |
# This file is part of Freedroid |
| 6 |
# |
| 7 |
# Freedroid 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 2 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Freedroid 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 Freedroid; see the file COPYING. If not, write to the |
| 19 |
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 |
# MA 02111-1307 USA |
| 21 |
# |
| 22 |
|
| 23 |
# xgettext can not handle several file formats in a POTFILES. |
| 24 |
# |
| 25 |
# This wrapper script loops on each file listed in a POTFILES, |
| 26 |
# calls xgettext for each file with the right language parameter, |
| 27 |
# concatenating all results in the destination pot file. |
| 28 |
# |
| 29 |
# For lua, dat and droids files, extract_strings() extracts the marked strings |
| 30 |
# and creates a pseudo c-code which is passed to xgettext. |
| 31 |
|
| 32 |
extract_strings() |
| 33 |
{ |
| 34 |
inf=$1 |
| 35 |
outf=$2 |
| 36 |
comment=$3 |
| 37 |
${AWK} ' |
| 38 |
/TRANSLATORS:/ { |
| 39 |
sub("--;", "//") |
| 40 |
print $0 |
| 41 |
next |
| 42 |
} |
| 43 |
/xgettext:/ { |
| 44 |
sub("--;", "//") |
| 45 |
print $0 |
| 46 |
next |
| 47 |
} |
| 48 |
/_"|_\[{2}/ { |
| 49 |
inline = $0 |
| 50 |
outline = "" |
| 51 |
postout = "" |
| 52 |
if (match(inline, "_\\[{2}([^\\]]+)$")) { |
| 53 |
stop = 0 |
| 54 |
while (stop == 0) { |
| 55 |
if (getline <= 0) { |
| 56 |
print inline "EOF but ]] expected" > "/dev/stderr" |
| 57 |
exit |
| 58 |
} |
| 59 |
inline = inline "\\n" $0 |
| 60 |
postout = postout "\n" |
| 61 |
if (match($0, "\\]{2}")) { |
| 62 |
stop = 1 |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
while (match(inline, "_\"([^\"]|\\\\\")+\"")) { |
| 67 |
match_start = RSTART |
| 68 |
match_length = RLENGTH |
| 69 |
outline = outline "a=_(" substr(inline, match_start+1, match_length-1) "); " |
| 70 |
inline = substr(inline, match_start + match_length) |
| 71 |
} |
| 72 |
while (match(inline, "_\\[{2}[^\\]]+\\]{2}")) { |
| 73 |
match_start = RSTART |
| 74 |
match_length = RLENGTH |
| 75 |
outline = outline "a=_(\"" substr(inline, match_start+3, match_length-5) "\"); " |
| 76 |
inline = substr(inline, match_start + match_length) |
| 77 |
} |
| 78 |
print outline postout |
| 79 |
next |
| 80 |
} |
| 81 |
{ print " " ; } |
| 82 |
' $1 > $2 |
| 83 |
} |
| 84 |
|
| 85 |
if [ $# -ne 0 ] ; then |
| 86 |
if [ $# -ne 0 ] ; then |
| 87 |
files_from="" |
| 88 |
domain="" |
| 89 |
directory="" |
| 90 |
declare -a ARGS |
| 91 |
j=1 |
| 92 |
for (( i=1 ; $i <= $# ; i+=1 )) ; do |
| 93 |
val=${!i#--files-from=} |
| 94 |
if [ " ${val}" != " ${!i}" ] ; then |
| 95 |
files_from="${val}" |
| 96 |
continue |
| 97 |
fi |
| 98 |
val=${!i#--default-domain=} |
| 99 |
if [ " ${val}" != " ${!i}" ] ; then |
| 100 |
domain="${val}" |
| 101 |
continue |
| 102 |
fi |
| 103 |
val=${!i#--directory=} |
| 104 |
if [ " ${val}" != " ${!i}" ] ; then |
| 105 |
directory="${val}" |
| 106 |
continue |
| 107 |
fi |
| 108 |
ARGS[$j]="${!i}" |
| 109 |
j+=1 |
| 110 |
done |
| 111 |
if [ " ${files_from}" != " " ] ; then |
| 112 |
first=1 |
| 113 |
out=$(mktemp XXX.pot) |
| 114 |
while read F ; do |
| 115 |
if [ " ${F:0:1}" != " #" ] ; then |
| 116 |
lang=C |
| 117 |
case ${F/*./} in |
| 118 |
"c" | "h" ) |
| 119 |
lang=C; |
| 120 |
from_directory=${directory};; |
| 121 |
"lua" | "dat" | "droids" ) |
| 122 |
lang=C; |
| 123 |
mkdir -p tmp/$(dirname $F); |
| 124 |
extract_strings ${directory}/$F tmp/$F; |
| 125 |
from_directory=tmp;; |
| 126 |
esac |
| 127 |
if (( ${first} )) ; then |
| 128 |
${SYS_XGETTEXT} "${ARGS[@]}" --directory=${from_directory} --language=${lang} -o ${out} $F |
| 129 |
first=0 |
| 130 |
else |
| 131 |
${SYS_XGETTEXT} "${ARGS[@]}" --directory=${from_directory} --language=${lang} -j -o ${out} $F |
| 132 |
fi |
| 133 |
fi |
| 134 |
done < ${files_from} |
| 135 |
mv ${out} ${domain}.po |
| 136 |
rm -rf tmp |
| 137 |
exit 0 |
| 138 |
fi |
| 139 |
fi |
| 140 |
${SYS_XGETTEXT} "$@" |
| 141 |
exit 0 |
| 142 |
fi |
| 143 |
echo "$0: Error. No arguments" |
| 144 |
exit 1 |