txpull.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/sh
  2. #
  3. # Fetch the Transifex translations for Calamares and incorporate them
  4. # into the source tree, adding commits of the different files.
  5. ### INITIAL SETUP
  6. #
  7. # This stuff needs to be done once; in a real CI environment where it
  8. # runs regularly in a container, the setup needs to be done when
  9. # creating the container.
  10. #
  11. #
  12. # cp ~/jenkins-master/.transifexrc ~ # Transifex user settings
  13. # cp ~/jenkins-master/.gitconfig ~ # Git config, user settings
  14. # cp -R ~/jenkins-master/.ssh ~ # SSH, presumably for github
  15. #
  16. # cd "$WORKSPACE"
  17. # git config --global http.sslVerify false
  18. test -f "CMakeLists.txt" || { echo "! Not at Calamares top-level" ; exit 1 ; }
  19. test -f ".tx/config" || { echo "! Not at Calamares top-level" ; exit 1 ; }
  20. test -f "calamares.desktop" || { echo "! Not at Calamares top-level" ; exit 1 ; }
  21. ### FETCH TRANSLATIONS
  22. #
  23. # Use Transifex client to get translations; this depends on the
  24. # .tx/config file to locate files, and overwrites them in the
  25. # filesystem with new (merged) translations.
  26. export QT_SELECT=5
  27. tx pull --force --source --all
  28. ### CLEANUP TRANSLATIONS
  29. #
  30. # Some languages have been deprecated. They may still exist in Transifex,
  31. # so clean them up after pulling.
  32. #
  33. drop_language() {
  34. rm -rf lang/python/"$1" src/modules/dummypythonqt/lang/"$1" lang/calamares_"$1".ts
  35. grep -v "\\[$1]" calamares.desktop > calamares.desktop.new
  36. mv calamares.desktop.new calamares.desktop
  37. }
  38. drop_language es_ES
  39. drop_language pl_PL
  40. # Also fix the .desktop file, which has some fields removed by Transifex.
  41. #
  42. { cat calamares.desktop.in ; grep "\\[[a-zA-Z_@]*]=" calamares.desktop ; } > calamares.desktop.new
  43. mv calamares.desktop.new calamares.desktop
  44. ### COMMIT TRANSLATIONS
  45. #
  46. # Produce multiple commits (for the various parts of the i18n
  47. # infrastructure used by Calamares) of the updated translations.
  48. # Try to be a little smart about not committing trivial changes.
  49. # Who is credited with these CI commits
  50. AUTHOR="--author='Calamares CI <groot@kde.org>'"
  51. # Message to put after the module name
  52. BOILERPLATE="Automatic merge of Transifex translations"
  53. git add --verbose lang/calamares*.ts
  54. git commit "$AUTHOR" --message="i18n: [calamares] $BOILERPLATE" | true
  55. rm -f lang/desktop*.desktop
  56. awk '
  57. BEGIN {skip=0;}
  58. /^# Translations/ {skip=1;}
  59. {if (!skip || (length($0)>1 && $0 != "# Translations")) {
  60. skip=0; print $0;
  61. }}' < calamares.desktop > calamares.desktop.new
  62. mv calamares.desktop.new calamares.desktop
  63. git add --verbose calamares.desktop
  64. git commit "$AUTHOR" --message="i18n: [desktop] $BOILERPLATE" | true
  65. # Transifex updates the PO-Created timestamp also when nothing interesting
  66. # has happened, so drop the files which have just 1 line changed (the
  67. # PO-Created line). This applies only to modules which use po-files.
  68. git diff --numstat src/modules | awk '($1==1 && $2==1){print $3}' | xargs git checkout --
  69. # Go through the Python modules; those with a lang/ subdir have their
  70. # own complete gettext-based setup.
  71. for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do
  72. FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f)
  73. if test -n "$FILES" ; then
  74. MODULE_NAME=$(basename ${MODULE_DIR})
  75. if [ -d ${MODULE_DIR}/lang ]; then
  76. # Convert PO files to MO files
  77. for POFILE in $(find ${MODULE_DIR} -name "*.po") ; do
  78. sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
  79. msgfmt -o ${POFILE%.po}.mo $POFILE
  80. done
  81. git add --verbose ${MODULE_DIR}/lang/*
  82. git commit "$AUTHOR" --message="i18n: [${MODULE_NAME}] $BOILERPLATE" | true
  83. fi
  84. fi
  85. done
  86. for POFILE in $(find lang -name "python.po") ; do
  87. sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
  88. msgfmt -o ${POFILE%.po}.mo $POFILE
  89. done
  90. git add --verbose lang/python*
  91. git commit "$AUTHOR" --message="i18n: [python] $BOILERPLATE" | true
  92. # git push --set-upstream origin master