import-translations 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. set -e
  3. set -u
  4. EXCLUDE_LANGS='fr'
  5. TAILS_PO_DIR='po'
  6. SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
  7. TOR_TRANSLATION_REMOTE='https://git.torproject.org/translation.git'
  8. TOR_TRANSLATION_DIR="$SCRIPT_DIR/tmp/tor-translation"
  9. GIT_IN_TOR_TRANSLATION_DIR="git \
  10. --work-tree=\"$TOR_TRANSLATION_DIR\" \
  11. --git-dir=\"$TOR_TRANSLATION_DIR/.git\""
  12. ### External libraries
  13. . "$SCRIPT_DIR/config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh"
  14. lang_is_excluded () {
  15. local lang="$1"
  16. echo -n "$EXCLUDE_LANGS" | grep -qs -w "$lang"
  17. }
  18. # Defaults
  19. LANG_DOT_PO_LAYOUT=yes
  20. # Detect which project is in current folder,
  21. # and set parameters accordingly
  22. if [ -f 'po/tails.pot' ]; then
  23. BRANCH='tails-misc_completed'
  24. AFTER_IMPORT='intltool_update_po $(po_languages)'
  25. elif [ -f 'po/tails-greeter.pot' ]; then
  26. BRANCH='tails-greeter_completed'
  27. AFTER_IMPORT='./setup.py build_i18n'
  28. elif [ -f 'po/tails-iuk.pot' ]; then
  29. BRANCH='tails-iuk_completed'
  30. AFTER_IMPORT='make -C po pot && make -C po update-po'
  31. elif [ -f 'po/onioncircuits.pot' ]; then
  32. LANG_DOT_PO_LAYOUT=no
  33. POTFILE=onioncircuits.pot
  34. BRANCH='tails-onioncircuits_completed'
  35. AFTER_IMPORT='./setup.py build_i18n && ( cd po && for po in *.po ; do msgmerge --update "$po" onioncircuits.pot ; done )'
  36. elif [ -f 'po/tails-perl5lib.pot' ]; then
  37. BRANCH='tails-perl5lib_completed'
  38. AFTER_IMPORT='make -C po pot && make -C po update-po'
  39. elif [ -f 'po/tails-installer.pot' ]; then
  40. BRANCH='liveusb-creator_completed'
  41. AFTER_IMPORT='./setup.py build && cd po && for po in *.po ; do msgmerge --update "$po" tails-installer.pot ; done'
  42. elif [ -f 'po/tails-persistence-setup.pot' ]; then
  43. BRANCH='tails-persistence-setup_completed'
  44. AFTER_IMPORT='make -C po pot && make -C po update-po'
  45. elif [ -f 'po/whisperback.pot' ]; then
  46. BRANCH='whisperback_completed'
  47. AFTER_IMPORT=''
  48. else
  49. echo "Current folder is not a project known to this script!"
  50. exit 1
  51. fi
  52. # Clone or update the translation repository
  53. if [ -d "$TOR_TRANSLATION_DIR" ]; then
  54. eval "$GIT_IN_TOR_TRANSLATION_DIR fetch origin"
  55. else
  56. mkdir -p "$SCRIPT_DIR/tmp"
  57. git clone "$TOR_TRANSLATION_REMOTE" "$TOR_TRANSLATION_DIR"
  58. fi
  59. # Checkout the correct branch
  60. eval "$GIT_IN_TOR_TRANSLATION_DIR checkout \"$BRANCH\""
  61. eval "$GIT_IN_TOR_TRANSLATION_DIR reset --hard \"origin/$BRANCH\""
  62. # For each completely translated language, merge it,
  63. # unless it is translated outside Transifex
  64. if [ "$LANG_DOT_PO_LAYOUT" = yes ] ; then
  65. find "$TOR_TRANSLATION_DIR" -name '*.po' | while read po_file; do
  66. lang=$(basename "$po_file" | tr - _ | sed 's/\.po$//')
  67. if ! lang_is_excluded "$lang"; then
  68. echo "Importing translation for $lang..."
  69. cp "$po_file" "$TAILS_PO_DIR"
  70. fi
  71. done
  72. else
  73. find "$TOR_TRANSLATION_DIR" -name '*.pot' | while read po_file; do
  74. lang=$(basename $(dirname "$po_file" | tr - _ | sed 's/\.pot$//'))
  75. if ! lang_is_excluded "$lang"; then
  76. echo "Importing translation for $lang..."
  77. cp "$po_file" "$TAILS_PO_DIR/${lang}.po"
  78. fi
  79. done
  80. fi
  81. # Update PO files
  82. if [ -n "${AFTER_IMPORT:-}" ]; then
  83. eval "$AFTER_IMPORT"
  84. fi