refresh-translations 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #! /bin/sh
  2. set -e
  3. set -u
  4. PERL_PROGS="/usr/local/bin/tails-security-check \
  5. /usr/local/lib/tails-htp-notify-user \
  6. /usr/local/lib/tails-virt-notify-user"
  7. PYTHON_PROGS="/etc/whisperback/config.py \
  8. /usr/local/bin/tails-about /usr/local/sbin/tails-additional-software"
  9. SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
  10. /usr/local/bin/electrum \
  11. /usr/local/bin/icedove \
  12. /usr/local/bin/tails-upgrade-frontend-wrapper \
  13. /usr/local/lib/tails-spoof-mac \
  14. /usr/local/sbin/tails-i2p \
  15. /usr/local/sbin/i2p-browser \
  16. /usr/local/bin/tor-browser \
  17. /usr/local/sbin/unsafe-browser"
  18. JAVASCRIPT_PROGS=" \
  19. /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js \
  20. /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
  21. "
  22. LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
  23. ### External libraries
  24. . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
  25. ### Functions
  26. prog_potfile () {
  27. prog=$1
  28. progpath="config/chroot_local-includes$prog"
  29. case $prog in
  30. /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js)
  31. domain=shutdown-helper-extension.js
  32. ;;
  33. *)
  34. domain=$(basename $prog)
  35. ;;
  36. esac
  37. echo "tmp/pot/${domain}.pot"
  38. }
  39. refresh_pot () {
  40. prog=$1
  41. proglang=$2
  42. progpath="config/chroot_local-includes$prog"
  43. pot=$(prog_potfile $prog)
  44. mkdir -p "$(dirname $pot)"
  45. if [ -e "${progpath}" ]; then
  46. xgettext --language="${proglang}" --from-code=UTF-8 \
  47. -o "${pot}" "${progpath}"
  48. sed -i "s@^\"Content-Type: text/plain\; charset=CHARSET\\\n\"@\"Content-Type: text/plain\; charset=UTF-8\\\n\"@" "${pot}"
  49. fi
  50. }
  51. po_file () {
  52. locale=$1
  53. echo "po/${locale}.po"
  54. }
  55. mo_file () {
  56. locale=$1
  57. echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
  58. }
  59. refresh_mo () {
  60. for locale in "$@" ; do
  61. po=$(po_file $locale)
  62. mo=$(mo_file $locale)
  63. mkdir -p $(dirname "$mo")
  64. msgfmt -o "${mo}" "${po}"
  65. done
  66. }
  67. no_left_out_files () {
  68. (cd po && intltool-update --maintain)
  69. [ ! -e po/missing ] || return 1
  70. return 0
  71. }
  72. intltool_update_pot () {
  73. (
  74. cd po
  75. intltool-update --pot --gettext-package=tails
  76. )
  77. }
  78. intltool_merge () {
  79. grep -E --no-filename '[^ #]*\.(desktop|directory)\.in$' po/POTFILES.in \
  80. | while read infile ; do
  81. intltool-merge --quiet --desktop-style --utf8 \
  82. po "$infile" "${infile%.in}"
  83. done
  84. }
  85. ### Main
  86. # Update POT files
  87. mkdir -p tmp/pot
  88. for prog in $PERL_PROGS ; do refresh_pot $prog Perl ; done
  89. for prog in $PYTHON_PROGS ; do refresh_pot $prog Python ; done
  90. for prog in $SHELL_PROGS ; do refresh_pot $prog Shell ; done
  91. for prog in $JAVASCRIPT_PROGS ; do refresh_pot $prog JavaScript ; done
  92. intltool_update_pot
  93. # If left out files are detected, intltool-update --maintain writes
  94. # them to po/missing.
  95. no_left_out_files || exit 3
  96. # Update PO files
  97. intltool_update_po $(po_languages)
  98. # Update files that are actually used at runtime
  99. refresh_mo $(po_languages)
  100. intltool_merge