opie_i18n.bbclass 5.7 KB

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