5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # author: Michael Gerz, michael.gerz@teststep.org
10 # This script extracts some information from the po file headers (last
11 # translator, revision date), generates the corresponding gmo files
12 # to retrieve the number of translated/fuzzy/untranslated messages,
13 # and generates a PHP web page.
16 # postats.sh po_files > "pathToWebPages"/i18n.inc
18 # modify this when you change version
19 # Note that an empty lyx_branch variable (ie svn trunk)
20 # will "do the right thing".
25 # GNU sed and grep have real problems dealing with 8-bit characters
26 # in UTF-8 encoded environments.
42 # '588 translated messages, 1248 fuzzy translations, 2 untranslated messages.'
43 # Any one of these substrings may not appear if the associated number is 0.
45 # $2 is the word following the number to be extracted,
46 # ie, 'translated', 'fuzzy', or 'untranslated'.
48 # extract_number fills var $number with this number, or sets it to zero if the
49 # word is not found in the string.
51 test $# -eq 2 || error 'extract_number expects 2 args'
54 echo $1 | grep $2 >/dev/null || return
55 # It /is/ safe to use 'Z' as a delimiter here.
56 number=`echo $1 | sed "s/\([0-9]*\)[ ]*$2/Z\1Z/" | cut -d 'Z' -f 2`
60 # $template is used by run_msgfmt, below, to fill $output. The function extracts
61 # the appropriate values from the data.
62 template="array ( 'langcode' => 'LC',
63 \"msg_tr\" => TR, \"msg_fu\" => FU, \"msg_nt\" => NT,
64 \"translator\" => \"AUTHOR\", \"email\" => \"EMAIL\",
65 \"date\" => \"DATE\" )"
69 # $1 is the name of the po file.
71 # The function runs msgfmt on it and fills var $output.
72 # All other variables created in the function are unset on exit.
74 test $# -eq 1 || error 'run_msgfmt expects 1 arg'
78 warning "File $1 does not exist"
85 gmofile=`echo $pofile | sed 's/po$/gmo/'`
86 test $pofile != '' -a $pofile != $gmofile || {
87 warning "File $1 is not a po file"
88 unset origdir dir pofile gmofile
95 langcode=`echo $pofile | sed 's/\.po$//'`
97 # Searching for a string of the form
98 # '"PO-Revision-Date: 2003-01-18 03:00+0100\n"'
99 date=`grep 'Revision-Date' $pofile | sed 's/ */ /g' | cut -d ' ' -f 2`
101 # Searching for a string of the form
102 # '"Last-Translator: Michael Gerz <Michael.Gerz@teststep.org>\n"'
105 input=`grep "Last-Translator" $pofile` && {
106 input=`echo $input | sed 's/ */ /g' | cut -d ' ' -f 2-`
108 translator=`echo $input | cut -d '<' -f 1 | sed 's/ *$//'`
109 email=`echo $input | cut -d '<' -f 2 | cut -d '>' -f 1 | sed -e 's/@/ () /' -e 's/\./ ! /g'`
113 # Does $translator contain 8-bit characters?
115 echo $translator | grep "[^${TAB} -~]" >/dev/null && {
116 # If so, grab the encoding from the po file.
117 charset=`sed -n '/Content-Type/{s/.*charset=//;s/\\\\n" *$//p;q}' $pofile`
118 # Use recode to generate HTML character codes for the 8-bit
120 translator=`echo $translator | recode "${charset}..h4"` || exit 1
121 # The ampersands in the $translator entries will mess things
122 # up unless we escape 'em.
123 translator=`echo $translator | sed 's/&/\\\&/g'`
126 # Run msgfmt on the pofile, filling $message with the raw info.
127 message=`$msgfmt --statistics -o $gmofile $pofile 2>&1 | grep "^[1-9]"` || {
128 warning "Unable to run msgfmt successfully on file $1"
130 unset origdir pofile gmofile
135 extract_number "$message" 'translated'
138 extract_number "$message" 'fuzzy'
141 extract_number "$message" 'untranslated'
145 output=`echo "$template" | sed "s/LC/$langcode/; \
146 s/TR/$translated/; s/FU/$fuzzy/; s/NT/$untranslated/; \
147 s/AUTHOR/$translator/; s/EMAIL/$email/; s/DATE/$date/"`
149 unset langcode date translator email untranslated fuzzy translated
155 # The head of the generated php file.
157 test "$lyx_branch" = "" && {
160 branch_tag="branches/$lyx_branch"
165 // The current version
166 \$lyx_version = "$lyx_version";
168 \$branch_tag = "$branch_tag";
176 # The foot of the generated php file.
185 # The main body of the script
186 msgfmt=`which msgfmt`
187 test $msgfmt != '' || error "Unable to find 'msgfmt'. Cannot proceed."
195 if [ $# -eq 0 ]; then