summaryrefslogtreecommitdiff
path: root/classes/opie_i18n.oeclass
blob: 9e8e3f59f7778707f85f5636e709f3f6e552349e (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# classes/opie_i18n.oeclass 		Matthias 'CoreDump' Hentges			16-10-2004          
#
# Automatically builds i18n ipks for opie packages. It downloads opie-i18n from opie CVS
# and tries to guess the name of the .ts file based on the package name:
# ${PN}.ts, lib${PN}.ts and opie-${PN}.ts are all valid. The .ts "guessing" can be
# disabled by setting I18N_FILES in the .oe file.
#
# Todo:
#

I18N_STATS = "1"
SRC_URI += "cvs://anoncvs:anoncvs@cvs.handhelds.org/cvs;module=opie/i18n" 
DEPENDS += "opie-i18n"
	
die () {
	echo -e "opie_18n: ERROR: $1"
	exit 1
}	

python do_build_opie_i18n_data() {

	import os, oe, re
	workdir = oe.data.getVar("WORKDIR", d, 1)
	packages = oe.data.getVar("PACKAGES", d, 1)
	files = oe.data.getVar("FILES", d, 1)
	section = oe.data.getVar("SECTION", d, 1)
	pn = oe.data.getVar("PN", d, 1)
	rdepends =  oe.data.getVar("RDEPENDS", d, 1)
	
	if os.path.exists(workdir + "/PACKAGES.tmp"):
		fd = open(workdir + "/PACKAGES.tmp", 'r')
		lines = fd.readlines()
		fd.close()
	
		oe.data.setVar('PACKAGES', " ".join(lines).lower() + " " + packages, d)	

		fd = open(workdir + "/FILES.tmp", 'r')
		lines = fd.readlines()
		fd.close()

		for l in lines:			
			x = re.split("\#", l)
			oe.data.setVar('FILES_%s' % x[0].lower(), " " + x[1].strip('\n'), d)
			oe.data.setVar('SECTION_%s' % x[0].lower(), "opie/translations", d)
			oe.data.setVar('RDEPENDS_%s' % x[0].lower(), pn, d)

		oe.data.setVar('SECTION_%s' % pn, section, d)
		oe.data.setVar('RDEPENDS', rdepends, d)
	else:
		oe.note("No translations found for package " + pn)
}
	
do_build_opie_i18n () {

	cd "${WORKDIR}/i18n" || die "ERROR:\nCouldn't find Opies i18n sources in ${PN}/i18n\nMake sure that <inherit opie_i18n> or <inherit opie> is *below* <SRC_URIS =>!"
	
	if test -z "${I18N_FILES}"
	then
		package_name="`echo "${PN}"| sed "s/^opie\-//"`"
		package_name2="`echo "${PN}"| sed "s/^opie\-//;s/\-//"`"
		test "$package_name" != "$package_name2" && I18N_FILES="${package_name}.ts lib${package_name}.ts opie-${package_name}.ts ${package_name2}.ts lib${package_name2}.ts opie-${package_name2}.ts"
		test "$package_name" = "$package_name2" && I18N_FILES="${package_name}.ts lib${package_name}.ts opie-${package_name}.ts"
		echo -e "I18N Datafiles: ${I18N_FILES} (auto-detected)\nYou can overide the auto-detection by setting I18N_FILES in your .oe file"
	else
		echo "I18N Datafiles: ${I18N_FILES} (provided by .oe)"
	fi	
	
	rm -f "${WORKDIR}/FILES.tmp" "${WORKDIR}/PACKAGES.tmp"
	
	echo -e "\nFILES is set to [${FILES}]\n"
	
	for file in ${I18N_FILES}
	do
		echo "Working on [$file]"
		for ts_file in `ls -1 */*.ts | egrep "/$file"`
		do
			echo -e "\tCompiling [$ts_file]"
			cd "${WORKDIR}/i18n/`dirname $ts_file`" || die "[${WORKDIR}/i18n/`dirname $ts_file`] not found"
			opie-lrelease "`basename $ts_file`" || die "lrelease failed! Make sure that <inherit opie_i18n> or <inherit opie> is *below* <DEPENDS =>!"							
			
			# $lang is the language as in de_DE, $lang_sane replaces "_" with "-"
			# to allow packaging as "_" is not allowed in a package name
			lang="`echo "$ts_file" | sed -n "s#\(.*\)/\(.*\)#\1#p"`"
			lang_sane="`echo "$ts_file" | sed -n "s#\(.*\)/\(.*\)#\1#p"|sed s/\_/\-/`"
			echo -e "\tPackaging [`basename $ts_file`] for language [$lang]"
			
			install -d ${D}${palmtopdir}/i18n/$lang			
			install -m 0644 ${WORKDIR}/i18n/$lang/.directory ${D}${palmtopdir}/i18n/$lang/
			install -m 0644 ${WORKDIR}/i18n/$lang/*.qm "${D}${palmtopdir}/i18n/$lang/"
						
			# As it is not possible to modify OE vars from within a _shell_ function,
			# some major hacking was needed. These two files will be read by the python 
			# function do_build_opie_i18n_data() which sets the variables FILES_* and
			# PACKAGES as needed. 
			echo -n "${PN}-${lang_sane} " >> "${WORKDIR}/PACKAGES.tmp"						
			echo -e "${PN}-${lang_sane}#${palmtopdir}/i18n/$lang" >> "${WORKDIR}/FILES.tmp"								
			
			ts_found_something=1
		done
		
		if test "$ts_found_something" != 1
		then
			echo -e "\tNo translations found"
		else
			ts_found_something=""
			ts_found="$ts_found $file"
		fi
				
		# Only used for debugging purposes
		test "${I18N_STATS}" = 1 && cd "${WORKDIR}/i18n"	

		echo -e "Completed [$file]\n\n"
	done	

	qt_dirs="apps  bin  etc  lib  pics  plugins  share  sounds"

	for dir in $qt_dirs
	do
		dir_="$dir_ ${palmtopdir}/$dir "
	done

	
	# If we don't adjust FILES to exclude the i18n directory, we will end up with
	# _lots_ of empty i18n/$lang directories in the original .ipk.	
	if (echo "${FILES}" | egrep "/opt/QtPalmtop/? |/opt/QtPalmtop/?$") &>/dev/null
	then
		echo "NOTE: FILES was set to /opt/QtPalmtop which would include the i18n directory"
		echo -e "\n\nI'll remove /opt/QtPalmtop from FILES and replace it with all directories"
		echo "below QtPalmtop, except i18n ($qt_dirs). See classes/opie_i18n.oeclass for details"

		# Removes /opt/QtPalmtop from FILES but keeps /opt/QtPalmtop/$some_dir
		FILES="`echo "$FILES"| sed "s#/opt/QtPalmtop[/]\?\$\|/opt/QtPalmtop[/]\? ##"`"

		echo "${PN}#$FILES $dir_" >> "${WORKDIR}/FILES.tmp"
	fi

	# This is the common case for OPIE apps which are installed by opie.oeclass magic
	if test -z "${FILES}"
	then
		echo "NOTE:"
		echo -e "Since FILES is empty, i'll add all directories below /o/QtPalmtop to it,\nexcluding i18n: ( $qt_dirs )"
		echo "${PN}#$FILES $dir_" >> "${WORKDIR}/FILES.tmp"
	fi	
	
	if ! test -e "${WORKDIR}/PACKAGES.tmp" -a "${I18N_STATS}" = 1
	then
		echo "No translations for package [${PN}]" >> /tmp/oe-i18n-missing.log
	else
		echo "Using [$ts_found ] for package [${PN}]" >> /tmp/oe-i18n.log
	fi
	
	# While this might not be very elegant, it safes a _ton_ of space (~30Mb) for
	# each opie package.
	for file in $(ls */*.ts | egrep -v "`echo "$ts_found"| sed "s/^\ //;s/\ /\|/"`")
	do
		rm "$file"
	done
	
	return 0
}

addtask build_opie_i18n before do_compile
addtask build_opie_i18n_data after do_build_opie_i18n before do_compile