| 1 |
#!/bin/sh
|
| 2 |
|
| 3 |
# This script is used for translations using .po files.
|
| 4 |
# It creates the initial .po files for a language where there
|
| 5 |
# already is a translation.
|
| 6 |
|
| 7 |
# This script is meant to be used only once for the transition
|
| 8 |
# from translating the .xml files to using .po files.
|
| 9 |
|
| 10 |
if [ "$1" = "--help" ] ; then
|
| 11 |
echo "Usage: $0 <language>"
|
| 12 |
exit 0
|
| 13 |
fi
|
| 14 |
|
| 15 |
language=${1:-pl}
|
| 16 |
|
| 17 |
[ -d ./$language/ ] || exit 1
|
| 18 |
|
| 19 |
SCRIPTDIR="./scripts"
|
| 20 |
WORKDIR="./integrated"
|
| 21 |
SOURCEDIR="$WORKDIR/$language"
|
| 22 |
PODIR="./po"
|
| 23 |
|
| 24 |
if [ -d "$PODIR" ] ; then
|
| 25 |
echo "Deleting old .po files for '$language'..."
|
| 26 |
for i in `find $PODIR/ -name "*.$language.po"` ; do
|
| 27 |
rm $i
|
| 28 |
done
|
| 29 |
else
|
| 30 |
echo "Error: directory $PODIR does not exist."
|
| 31 |
exit 1
|
| 32 |
fi
|
| 33 |
|
| 34 |
XMLLIST=$(find $SOURCEDIR -name "*.xml")
|
| 35 |
|
| 36 |
echo "Creating .po files for language '$language'..."
|
| 37 |
|
| 38 |
export NO_CREDITS=1 # Repress KDE specific credits
|
| 39 |
# Note: not yet supported by split2po
|
| 40 |
|
| 41 |
for SOURCEXML in $XMLLIST ; do
|
| 42 |
SUBDIR=$(dirname $SOURCEXML | sed "s:$SOURCEDIR::" | sed "s:^/::")
|
| 43 |
if [ ! -d $PODIR/$SUBDIR ] ; then
|
| 44 |
echo "Skipping $SUBDIR; directory does not exist under $PODIR"
|
| 45 |
continue
|
| 46 |
fi
|
| 47 |
XML=$(basename $SOURCEXML)
|
| 48 |
ORIGXML=$WORKDIR/en/$SUBDIR/$XML
|
| 49 |
PO=$PODIR/$SUBDIR/$(basename $SOURCEXML .xml).$language.po
|
| 50 |
|
| 51 |
echo "Converting translated $SUBDIR/$XML to .po file"
|
| 52 |
split2po $ORIGXML $SOURCEXML >$PO
|
| 53 |
if [ $? -ne 0 ] ; then
|
| 54 |
echo "** Error during conversion."
|
| 55 |
continue
|
| 56 |
fi
|
| 57 |
|
| 58 |
continue
|
| 59 |
# Remove strange references created by split2po
|
| 60 |
# Note: this is a workaround for a bug in the tools:
|
| 61 |
# http://bugs.kde.org/show_bug.cgi?id=90112
|
| 62 |
# Can be removed when NO_CREDITS=1 is supported by split2po
|
| 63 |
if grep -q "POXML_" $PO ; then
|
| 64 |
echo " Converting "POXML_" references..."
|
| 65 |
cat $PO | \
|
| 66 |
sed "s/!POXML_AMP!/\&/g" | \
|
| 67 |
sed "s/ /\\\t/g" | \
|
| 68 |
sed "s/&POXML_SPACE;/ /g" | \
|
| 69 |
sed "s/&POXML_LINEFEED;/\\\n\"\n \"/g" | \
|
| 70 |
sed "s/&POXML_LT;/</g" | \
|
| 71 |
sed "s/&POXML_GT;/>/g" \
|
| 72 |
>/tmp/tmp.po.$$
|
| 73 |
cp /tmp/tmp.po.$$ $PO
|
| 74 |
fi
|
| 75 |
# Check if there are any we don't yet know about
|
| 76 |
if grep "POXML_" $PO ; then
|
| 77 |
echo "** Error: file contains unknown "POXML_" references."
|
| 78 |
fi
|
| 79 |
|
| 80 |
# Remove spurious msgid's created by split2po (drop last 6 lines)
|
| 81 |
# Note: this is a workaround for a feature in the tools:
|
| 82 |
# http://bugs.kde.org/show_bug.cgi?id=90112
|
| 83 |
if grep "ROLES_OF_TRANSLATORS" $PO >/dev/null; then
|
| 84 |
LINES=$(cat $PO | wc -l)
|
| 85 |
head -n $(($LINES - 6)) $PO >/tmp/tmp.po.$$
|
| 86 |
cp /tmp/tmp.po.$$ $PO
|
| 87 |
fi
|
| 88 |
done
|
| 89 |
|
| 90 |
# Check the results
|
| 91 |
echo ""
|
| 92 |
echo "Checking whether translation matches corresponding .pot file..."
|
| 93 |
for PO in `find $PODIR -name "*.$language.po"` ; do
|
| 94 |
TDIR=$(dirname $PO); POT=$(basename $PO ".$language.po").pot
|
| 95 |
if [ -s $PO ] ; then
|
| 96 |
if [ -f $TDIR/$POT ] ; then
|
| 97 |
count_POT=$(egrep "^msgid " $TDIR/$POT | wc -l)
|
| 98 |
count_PO=$(egrep "^msgstr " $PO | wc -l)
|
| 99 |
if [ $count_PO != $count_POT ] ; then
|
| 100 |
echo "** Warning: translation for $PO has $count_PO strings, while original has $count_POT strings."
|
| 101 |
fi
|
| 102 |
# Missing strings: If a line with 'msgstr ""' is followed by an empty line.
|
| 103 |
count_missing_PO=$(egrep -A 1 "^msgstr \"\"$" $PO | egrep "^$" | wc -l)
|
| 104 |
if [ $count_missing_PO -ne 0 ] ; then
|
| 105 |
echo "** Warning: translation for $PO has $count_missing_PO missing strings."
|
| 106 |
fi
|
| 107 |
else
|
| 108 |
echo "** Error: corresponding .pot file not found for $PO."
|
| 109 |
fi
|
| 110 |
else
|
| 111 |
echo "** Error: $PO is empty (conversion error)."
|
| 112 |
fi
|
| 113 |
done
|
| 114 |
echo "Done."
|
| 115 |
|
| 116 |
# Checking for untranslated strings
|
| 117 |
echo ""
|
| 118 |
echo "Checking for untranslated strings in the .po files..."
|
| 119 |
for PO in `find po/ -name "*.$language.po"` ; do
|
| 120 |
echo "Checking $PO..."
|
| 121 |
awk -f $SCRIPTDIR/mark_untranslated.awk $PO
|
| 122 |
done
|
| 123 |
|
| 124 |
echo ""
|
| 125 |
echo "The conversion has finished successfully."
|
| 126 |
echo "The .po files for $language have been saved in '$PODIR'."
|
| 127 |
echo ""
|
| 128 |
echo "Please check all messages above very carefully."
|
| 129 |
echo "If any translations are shown to have a different amount of strings than the original,"
|
| 130 |
echo "you should probably correct the cause of this and run the conversion again."
|
| 131 |
echo ""
|
| 132 |
echo "Strings that are shown as 'looking untranslated', this could just be a string that"
|
| 133 |
echo "does not need translation, but could also indicate parts of the original that really"
|
| 134 |
echo "are untranslated but are not marked as such."
|
| 135 |
echo "In that case, you can use the set_untranslated script to mark these strings as"
|
| 136 |
echo "untranslated (enter 'set_untranslated --help' for usage)."
|
| 137 |
|
| 138 |
rm /tmp/tmp.po.$$ /tmp/$$.xml &>/dev/null
|
| 139 |
exit 0
|