| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
#I wrote this because autoconf is confusing as bloody hell. |
| 4 |
#I just need to copy some files into a place where gettext will expect them |
| 5 |
#I Shouldn't need to create some mega ultimate makefile.am for that, then |
| 6 |
#follow some random poorly documented hierarchy and naming system. (Looking at you gettextize!) |
| 7 |
|
| 8 |
#Usage: makeTranslation [install|update] |
| 9 |
|
| 10 |
#extract program name from sources -- Now with added case sensitivity hack! |
| 11 |
PROGRAM_NAME=`cat ../src/common/constants.cpp | grep PROGRAM_NAME | awk -F= '{print $2}' | sed 's/;//g' | sed 's/\"//g' | sed 's/;//' | sed 's/^\s*//'` |
| 12 |
#Where do we want to install the translations? (if using this script). |
| 13 |
TRANSLATION_INSTALL="/home/pcuser/mingw64/code/3Depict/locale/" |
| 14 |
|
| 15 |
#Space separated list of maintained locales |
| 16 |
MAINTAINED_LOCALES="de_DE fr_FR es_ES" |
| 17 |
|
| 18 |
echo "Program name is $PROGRAM_NAME" |
| 19 |
|
| 20 |
if [ x"$PROGRAM_NAME" == x"" ] ; then |
| 21 |
echo "Unable to extract program name. Aborting" |
| 22 |
exit 1; |
| 23 |
fi |
| 24 |
|
| 25 |
|
| 26 |
if [ $# -eq 0 ] ; then |
| 27 |
|
| 28 |
echo "Creating binary translation files.." |
| 29 |
#Create binary versions of gettext translation files |
| 30 |
for i in *.po |
| 31 |
do |
| 32 |
#Quick check to see if we have any "<span>" elements in the files |
| 33 |
if [ x"`grep '<span' $i `" != x"" ] ; then |
| 34 |
echo "WARNING: Detected \"span\" element in translation file. This is probably an error, due to encoding of special characters by transifex" |
| 35 |
fi |
| 36 |
msgfmt -c -v -o `echo $i | sed 's/po$/mo/'` $i |
| 37 |
done |
| 38 |
echo "done" |
| 39 |
exit 0 |
| 40 |
fi |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
if [ $# -eq 1 ] ; then |
| 45 |
if [ $1 == "install" ] ; then |
| 46 |
#Delete any existing translation file in the install folder |
| 47 |
find ${TRANSLATION_INSTALL} -name \*.mo -exec rm {} \; |
| 48 |
|
| 49 |
#install each locale |
| 50 |
for i in $MAINTAINED_LOCALES |
| 51 |
do |
| 52 |
|
| 53 |
if [ ! -f ${PROGRAM_NAME}_${i}.mo ] ; then |
| 54 |
echo "WARNING: ${PROGRAM_NAME}-$i.mo is missing!!!" |
| 55 |
else |
| 56 |
|
| 57 |
#Ensure the translation folder is present.. |
| 58 |
# gettext has very specific requirements for .mo file location |
| 59 |
mkdir -p $TRANSLATION_INSTALL/$i/LC_MESSAGES/ |
| 60 |
echo "Copying locale $i to $TRANSLATION_INSTALL/$i/LC_MESSAGES/" |
| 61 |
cp ${PROGRAM_NAME}_$i.mo $TRANSLATION_INSTALL/$i/LC_MESSAGES/$PROGRAM_NAME.mo |
| 62 |
fi |
| 63 |
done |
| 64 |
fi |
| 65 |
|
| 66 |
|
| 67 |
if [ $1 == "update" ] ; then |
| 68 |
xgettext --from-code=utf-8 -k_ -kTRANS -kwxTRANS -kNTRANS -kwxNTRANS `find ../src/ -name *.cpp` `find ../src/ -name *.h` ../data/startup-tips.txt -o update.pot |
| 69 |
|
| 70 |
echo "Merging with maintained locales" |
| 71 |
for i in $MAINTAINED_LOCALES |
| 72 |
do |
| 73 |
msgmerge -N ${PROGRAM_NAME}_${i}.po update.pot > tmp.pot |
| 74 |
#replace the default headers from msgmerge |
| 75 |
THISYEAR=`date | awk '{print $6}'` |
| 76 |
sed -i "s/YEAR THE PACKAGE.*/$THISYEAR/" tmp.pot |
| 77 |
sed -i "s/SOME DESCRIPTIVE TITLE.*/Translation file for locale $i/" tmp.pot |
| 78 |
sed -i 's/PACKAGE package/3Depict package/' tmp.pot |
| 79 |
|
| 80 |
#overwrite po |
| 81 |
mv tmp.pot ${PROGRAM_NAME}_${i}.po |
| 82 |
|
| 83 |
done |
| 84 |
|
| 85 |
echo "Replacing base template" |
| 86 |
msgmerge -N ${PROGRAM_NAME}_base.pot update.pot > tmp.pot |
| 87 |
mv tmp.pot ${PROGRAM_NAME}_base.pot |
| 88 |
rm update.pot |
| 89 |
fi |
| 90 |
fi |