File: makeTranslations

package info (click to toggle)
3depict 0.0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 17,908 kB
  • sloc: cpp: 72,771; sh: 6,497; xml: 1,576; python: 326; makefile: 194; ansic: 186
file content (90 lines) | stat: -rwxr-xr-x 2,920 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash

#I wrote this because autoconf is confusing as bloody hell.
#I just need to copy some files into a place where gettext will expect them
#I Shouldn't need to create some mega ultimate makefile.am for that, then
#follow some random poorly documented hierarchy and naming system. (Looking at you gettextize!)

#Usage: makeTranslation [install|update]

#extract program name from sources -- Now with added case sensitivity hack!
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*//'`
#Where do we want to install the translations? (if using this script).
TRANSLATION_INSTALL="/usr/share/locale/"

#Space separated list of maintained locales
MAINTAINED_LOCALES="de_DE fr_FR es_ES"

echo "Program name is $PROGRAM_NAME"

if [ x"$PROGRAM_NAME" == x"" ] ; then
	echo "Unable to extract program name. Aborting"
	exit 1;
fi


if [ $# -eq 0 ] ; then

	echo "Creating binary translation files.."
	#Create binary versions of gettext translation files
	for i in *.po
	do
		#Quick check to see if we have any "<span>" elements in the files
		if  [ x"`grep '<span' $i `" != x"" ] ; then
			echo "WARNING: Detected \"span\" element in translation file. This is probably an error, due to encoding of special characters by transifex"
		fi
		msgfmt -c -v -o `echo $i | sed 's/po$/mo/'` $i
	done
	echo "done"
	exit 0
fi



if [ $# -eq 1 ] ; then
	if [ $1  == "install" ] ; then
		#Delete any existing translation file in the install folder
		find ${TRANSLATION_INSTALL} -name \*.mo -exec rm {} \;

		#install each locale
		for i in $MAINTAINED_LOCALES
		do

			if [ ! -f ${PROGRAM_NAME}_${i}.mo ] ; then
				echo "WARNING: ${PROGRAM_NAME}-$i.mo is missing!!!"
			else

				#Ensure the translation folder is present..
				# gettext has very specific requirements for .mo file location
				mkdir -p $TRANSLATION_INSTALL/$i/LC_MESSAGES/
				echo "Copying locale $i  to $TRANSLATION_INSTALL/$i/LC_MESSAGES/"
				cp ${PROGRAM_NAME}_$i.mo $TRANSLATION_INSTALL/$i/LC_MESSAGES/$PROGRAM_NAME.mo
			fi
		done
	fi
	
	
	if [ $1  == "update" ] ; then
		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

		echo "Merging with maintained locales"
		for i in $MAINTAINED_LOCALES
		do
			msgmerge -N ${PROGRAM_NAME}_${i}.po update.pot > tmp.pot
			#replace the default headers from msgmerge
			THISYEAR=`date | awk '{print $6}'`
			sed -i "s/YEAR THE PACKAGE.*/$THISYEAR/"  tmp.pot
			sed -i "s/SOME DESCRIPTIVE TITLE.*/Translation file for locale $i/"  tmp.pot
			sed -i 's/PACKAGE package/3Depict package/' tmp.pot

			#overwrite po
			mv tmp.pot ${PROGRAM_NAME}_${i}.po

		done
		
		echo "Replacing base template"
		msgmerge -N ${PROGRAM_NAME}_base.pot update.pot > tmp.pot
		mv tmp.pot ${PROGRAM_NAME}_base.pot
		rm update.pot
	fi
fi