txpull.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. ### COMMIT TRANSLATIONS
  29. #
  30. # Produce multiple commits (for the various parts of the i18n
  31. # infrastructure used by Calamares) of the updated translations.
  32. # Try to be a little smart about not committing trivial changes.
  33. # Who is credited with these CI commits
  34. AUTHOR="--author='Calamares CI <groot@kde.org>'"
  35. # Message to put after the module name
  36. BOILERPLATE="Automatic merge of Transifex translations"
  37. git add --verbose lang/calamares*.ts
  38. git commit "$AUTHOR" --message="[core] $BOILERPLATE" | true
  39. rm -f lang/desktop*.desktop
  40. awk '
  41. BEGIN {skip=0;}
  42. /^# Translations/ {skip=1;}
  43. {if (!skip || (length($0)>1 && $0 != "# Translations")) {
  44. skip=0; print $0;
  45. }}' < calamares.desktop > calamares.desktop.new
  46. mv calamares.desktop.new calamares.desktop
  47. git add --verbose calamares.desktop
  48. git commit "$AUTHOR" --message="[desktop] $BOILERPLATE" | true
  49. # Transifex updates the PO-Created timestamp also when nothing interesting
  50. # has happened, so drop the files which have just 1 line changed (the
  51. # PO-Created line). This applies only to modules which use po-files.
  52. git diff --numstat src/modules | awk '($1==1 && $2==1){print $3}' | xargs git checkout --
  53. # Go through the Python modules; those with a lang/ subdir have their
  54. # own complete gettext-based setup.
  55. for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do
  56. FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f)
  57. if test -n "$FILES" ; then
  58. MODULE_NAME=$(basename ${MODULE_DIR})
  59. if [ -d ${MODULE_DIR}/lang ]; then
  60. # Convert PO files to MO files
  61. for POFILE in $(find ${MODULE_DIR} -name "*.po") ; do
  62. sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
  63. msgfmt -o ${POFILE%.po}.mo $POFILE
  64. done
  65. git add --verbose ${MODULE_DIR}/lang/*
  66. git commit "$AUTHOR" --message="[${MODULE_NAME}] $BOILERPLATE" | true
  67. fi
  68. fi
  69. done
  70. for POFILE in $(find lang -name "python.po") ; do
  71. sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE
  72. msgfmt -o ${POFILE%.po}.mo $POFILE
  73. done
  74. git add --verbose lang/python*
  75. git commit "$AUTHOR" --message="[python] $BOILERPLATE" | true
  76. # git push --set-upstream origin master