import-strings.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/sh
  2. if [ "$OPENCONNECT_DIR" = "" ]; then
  3. OPENCONNECT_DIR=../openconnect
  4. fi
  5. if [ "$OPENCONNECT_BUILD_DIR" = "" ]; then
  6. OPENCONNECT_BUILD_DIR="$OPENCONNECT_DIR"
  7. fi
  8. # The openconnect.pot file is made available by a cron job on this server, along
  9. # with the project's web site which is also held in the git repository. There's
  10. # race condition here, if the server is updating as we run this script. But it's
  11. # unlikely that the string in question would move far, so it should be good enough.
  12. COMMIT="$(cd $OPENCONNECT_DIR && git rev-parse HEAD)"
  13. if ! echo $COMMIT | egrep -q "[a-f0-9]{40}"; then
  14. echo "Error: Failed to fetch commit ID from $OPENCONNECT_DIR"
  15. exit 1
  16. fi
  17. pushd $OPENCONNECT_BUILD_DIR
  18. make po/openconnect.pot || exit 1
  19. popd
  20. COMMIT=$(echo $COMMIT | cut -c1-10)
  21. GITWEB=http://git.infradead.org/users/dwmw2/openconnect.git/blob/${COMMIT}:/
  22. OUTFILE=openconnect-strings-$COMMIT.txt
  23. cat >$OUTFILE <<EOF
  24. This file contains strings from the OpenConnect VPN client, found at
  25. http://www.infradead.org/openconnect/ and browseable in gitweb at
  26. http://git.infradead.org/users/dwmw2/openconnect.git
  27. We do this because NetworkManager-openconnect authentication dialog
  28. uses a lot of strings from libopenconnect, which also need to be
  29. translated too if the user is to have a fully localised experience.
  30. For translators looking to see source comments in their original context
  31. in order to translate them properly, the URLs by each one will give a
  32. link to the original source code.
  33. EOF
  34. cat $OPENCONNECT_BUILD_DIR/po/openconnect.pot |
  35. while read -r line; do
  36. case "$line" in
  37. "#:"*)
  38. echo >>$OUTFILE
  39. # FIXME: If it was already in openconnect-strings.txt can we keep the
  40. # previous URL instead of using the latest commit, to reduce churn?
  41. for src in ${line###: }; do
  42. echo "// ${GITWEB}${src%%:*}#l${src##*:}" >>$OUTFILE
  43. done
  44. real_strings=yes
  45. ;;
  46. "msgid "*)
  47. if [ "$real_strings" = "yes" ]; then
  48. echo -n "_(${line##msgid }" >>$OUTFILE
  49. in_msgid=yes
  50. fi
  51. ;;
  52. "msgstr "*|"")
  53. if [ "$in_msgid" = "yes" ]; then
  54. in_msgid=no
  55. echo ");" >>$OUTFILE
  56. fi
  57. ;;
  58. *)
  59. if [ "$in_msgid" = "yes" ]; then
  60. echo >>$OUTFILE
  61. echo -n "$line" >>$OUTFILE
  62. fi
  63. ;;
  64. esac
  65. done
  66. MESSAGES=$(grep -c "^_(" openconnect-strings-$COMMIT.txt)
  67. echo "Got $MESSAGES messages from openconnect upstream"
  68. if [ "$MESSAGES" -lt 100 ]; then
  69. echo "Fewer than 100 messages? Something went wrong"
  70. rm openconnect-strings-$COMMIT.txt
  71. exit 1
  72. fi
  73. NEWSHA=$(grep -v ^// openconnect-strings-$COMMIT.txt | sha1sum)
  74. OLDSHA=$(grep -v ^// openconnect-strings.txt | sha1sum)
  75. if [ "$NEWSHA" != "$OLDSHA" ]; then
  76. echo New strings
  77. mv openconnect-strings-$COMMIT.txt openconnect-strings.txt
  78. else
  79. echo No new strings. Not changing openconnect-strings.txt
  80. rm openconnect-strings-$COMMIT.txt
  81. fi
  82. make -C po NetworkManager-openconnect.pot || exit 1
  83. for a in po/*.po ; do
  84. echo Comparing $a...
  85. if [ -r $OPENCONNECT_DIR/$a ]; then
  86. msgattrib -F --no-fuzzy $OPENCONNECT_DIR/$a > $a.openconnect 2>/dev/null
  87. msgmerge -q -N -F $a -C $a.openconnect po/NetworkManager-openconnect.pot > $a.merged
  88. msgmerge -q -N -F $a po/NetworkManager-openconnect.pot > $a.unmerged
  89. if ! cmp $a.merged $a.unmerged; then
  90. echo New changes for $a
  91. mv $a.merged $a
  92. fi
  93. rm -f $a.openconnect $a.merged $a.unmerged
  94. msgattrib -F --no-fuzzy $a > $a.nmo
  95. msgmerge -q -N -F $OPENCONNECT_DIR/$a -C $a.nmo $OPENCONNECT_BUILD_DIR/po/openconnect.pot > $OPENCONNECT_DIR/$a.merged
  96. msgmerge -q -N -F $OPENCONNECT_DIR/$a $OPENCONNECT_BUILD_DIR/po/openconnect.pot > $OPENCONNECT_DIR/$a.unmerged
  97. if ! cmp $OPENCONNECT_DIR/$a.merged $OPENCONNECT_DIR/$a.unmerged; then
  98. echo New changes for OpenConnect $a
  99. mv $OPENCONNECT_DIR/$a.merged $OPENCONNECT_DIR/$a
  100. fi
  101. rm -f $OPENCONNECT_DIR/$a.merged $OPENCONNECT_DIR/$a.unmerged $a.nmo
  102. fi
  103. done