summaryrefslogtreecommitdiffstats
path: root/meta/classes/opie_i18n.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/opie_i18n.bbclass')
-rw-r--r--meta/classes/opie_i18n.bbclass163
1 files changed, 163 insertions, 0 deletions
diff --git a/meta/classes/opie_i18n.bbclass b/meta/classes/opie_i18n.bbclass
new file mode 100644
index 0000000000..cb3d07de75
--- /dev/null
+++ b/meta/classes/opie_i18n.bbclass
@@ -0,0 +1,163 @@
1# classes/opie_i18n.oeclass Matthias 'CoreDump' Hentges 16-10-2004
2#
3# Automatically builds i18n ipks for opie packages. It downloads opie-i18n from opie CVS
4# and tries to guess the name of the .ts file based on the package name:
5# ${PN}.ts, lib${PN}.ts and opie-${PN}.ts are all valid. The .ts "guessing" can be
6# disabled by setting I18N_FILES in the .oe file.
7#
8# Todo:
9#
10
11I18N_STATS = "1"
12SRC_URI += "${HANDHELDS_CVS};module=opie/i18n"
13DEPENDS += "opie-i18n"
14
15die () {
16 echo -e "opie_18n: ERROR: $1"
17 exit 1
18}
19
20python do_build_opie_i18n_data() {
21
22 import os, bb, re
23 workdir = bb.data.getVar("WORKDIR", d, 1)
24 packages = bb.data.getVar("PACKAGES", d, 1)
25 files = bb.data.getVar("FILES", d, 1)
26 section = bb.data.getVar("SECTION", d, 1)
27 pn = bb.data.getVar("PN", d, 1)
28 rdepends = bb.data.getVar("RDEPENDS", d, 1)
29
30 if os.path.exists(workdir + "/PACKAGES.tmp"):
31 fd = open(workdir + "/PACKAGES.tmp", 'r')
32 lines = fd.readlines()
33 fd.close()
34
35 bb.data.setVar('PACKAGES', " ".join(lines).lower() + " " + packages, d)
36
37 fd = open(workdir + "/FILES.tmp", 'r')
38 lines = fd.readlines()
39 fd.close()
40
41 for l in lines:
42 x = re.split("\#", l)
43 bb.data.setVar('FILES_%s' % x[0].lower(), " " + x[1].strip('\n'), d)
44 bb.data.setVar('SECTION_%s' % x[0].lower(), "opie/translations", d)
45 bb.data.setVar('RDEPENDS_%s' % x[0].lower(), pn, d)
46
47 bb.data.setVar('SECTION_%s' % pn, section, d)
48 bb.data.setVar('RDEPENDS', rdepends, d)
49 else:
50 bb.note("No translations found for package " + pn)
51}
52
53do_build_opie_i18n () {
54
55 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 =>!"
56
57 if test -z "${I18N_FILES}"
58 then
59 package_name="`echo "${PN}"| sed "s/^opie\-//"`"
60 package_name2="`echo "${PN}"| sed "s/^opie\-//;s/\-//"`"
61 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"
62 test "$package_name" = "$package_name2" && I18N_FILES="${package_name}.ts lib${package_name}.ts opie-${package_name}.ts"
63 echo -e "I18N Datafiles: ${I18N_FILES} (auto-detected)\nYou can overide the auto-detection by setting I18N_FILES in your .oe file"
64 else
65 echo "I18N Datafiles: ${I18N_FILES} (provided by .bb)"
66 fi
67
68 rm -f "${WORKDIR}/FILES.tmp" "${WORKDIR}/PACKAGES.tmp"
69
70 echo -e "\nFILES is set to [${FILES}]\n"
71
72 for file in ${I18N_FILES}
73 do
74 echo "Working on [$file]"
75 for ts_file in `ls -1 */*.ts | egrep "/$file"`
76 do
77 echo -e "\tCompiling [$ts_file]"
78 cd "${WORKDIR}/i18n/`dirname $ts_file`" || die "[${WORKDIR}/i18n/`dirname $ts_file`] not found"
79 opie-lrelease "`basename $ts_file`" || die "lrelease failed! Make sure that <inherit opie_i18n> or <inherit opie> is *below* <DEPENDS =>!"
80
81 # $lang is the language as in de_DE, $lang_sane replaces "_" with "-"
82 # to allow packaging as "_" is not allowed in a package name
83 lang="`echo "$ts_file" | sed -n "s#\(.*\)/\(.*\)#\1#p"`"
84 lang_sane="`echo "$ts_file" | sed -n "s#\(.*\)/\(.*\)#\1#p"|sed s/\_/\-/`"
85 echo -e "\tPackaging [`basename $ts_file`] for language [$lang]"
86
87 install -d ${D}${palmtopdir}/i18n/$lang
88 install -m 0644 ${WORKDIR}/i18n/$lang/.directory ${D}${palmtopdir}/i18n/$lang/
89 install -m 0644 ${WORKDIR}/i18n/$lang/*.qm "${D}${palmtopdir}/i18n/$lang/"
90
91 # As it is not possible to modify OE vars from within a _shell_ function,
92 # some major hacking was needed. These two files will be read by the python
93 # function do_build_opie_i18n_data() which sets the variables FILES_* and
94 # PACKAGES as needed.
95 echo -n "${PN}-${lang_sane} " >> "${WORKDIR}/PACKAGES.tmp"
96 echo -e "${PN}-${lang_sane}#${palmtopdir}/i18n/$lang" >> "${WORKDIR}/FILES.tmp"
97
98 ts_found_something=1
99 done
100
101 if test "$ts_found_something" != 1
102 then
103 echo -e "\tNo translations found"
104 else
105 ts_found_something=""
106 ts_found="$ts_found $file"
107 fi
108
109 # Only used for debugging purposes
110 test "${I18N_STATS}" = 1 && cd "${WORKDIR}/i18n"
111
112 echo -e "Completed [$file]\n\n"
113 done
114
115 qt_dirs="apps bin etc lib pics plugins share sounds"
116
117 for dir in $qt_dirs
118 do
119 dir_="$dir_ ${palmtopdir}/$dir "
120 done
121
122
123 # If we don't adjust FILES to exclude the i18n directory, we will end up with
124 # _lots_ of empty i18n/$lang directories in the original .ipk.
125 if (echo "${FILES}" | egrep "${palmtopdir}/? |${palmtopdir}/?$") &>/dev/null
126 then
127 echo "NOTE: FILES was set to ${palmtopdir} which would include the i18n directory"
128 echo -e "\n\nI'll remove ${palmtopdir} from FILES and replace it with all directories"
129 echo "below QtPalmtop, except i18n ($qt_dirs). See classes/opie_i18n.oeclass for details"
130
131 # Removes /opt/QtPalmtop from FILES but keeps /opt/QtPalmtop/$some_dir
132 FILES="`echo "$FILES"| sed "s#${palmtopdir}[/]\?\$\|${palmtopdir}[/]\? ##"`"
133
134 echo "${PN}#$FILES $dir_" >> "${WORKDIR}/FILES.tmp"
135 fi
136
137 # This is the common case for OPIE apps which are installed by opie.oeclass magic
138 if test -z "${FILES}"
139 then
140 echo "NOTE:"
141 echo -e "Since FILES is empty, i'll add all directories below ${palmtopdir} to it,\nexcluding i18n: ( $qt_dirs )"
142 echo "${PN}#$FILES $dir_" >> "${WORKDIR}/FILES.tmp"
143 fi
144
145 if ! test -e "${WORKDIR}/PACKAGES.tmp" -a "${I18N_STATS}" = 1
146 then
147 echo "No translations for package [${PN}]" >> /tmp/oe-i18n-missing.log
148 else
149 echo "Using [$ts_found ] for package [${PN}]" >> /tmp/oe-i18n.log
150 fi
151
152 # While this might not be very elegant, it safes a _ton_ of space (~30Mb) for
153 # each opie package.
154 for file in $(ls */*.ts | egrep -v "`echo "$ts_found"| sed "s/^\ //;s/\ /\|/"`")
155 do
156 rm "$file"
157 done
158
159 return 0
160}
161
162addtask build_opie_i18n before do_compile
163addtask build_opie_i18n_data after do_build_opie_i18n before do_compile