updatepo.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. # Update/create luanti po files
  3. # an auxiliary function to abort processing with an optional error
  4. # message
  5. abort() {
  6. test -n "$1" && echo >&2 "$1"
  7. exit 1
  8. }
  9. # The po/ directory is assumed to be parallel to the directory where
  10. # this script is. Relative paths are fine for us so we can just
  11. # use the following trick (works both for manual invocations and for
  12. # script found from PATH)
  13. scriptisin="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  14. # The script is executed from the parent of po/, which is also the
  15. # parent of the script directory and of the src/ directory.
  16. # We go through $scriptisin so that it can be executed from whatever
  17. # directory and still work correctly
  18. cd "$scriptisin/.."
  19. test -e po || abort "po/ directory not found"
  20. test -d po || abort "po/ is not a directory!"
  21. # Get a list of the languages we have to update/create
  22. cd po || abort "couldn't change directory to po!"
  23. # This assumes that we won't have dirnames with space, which is
  24. # the case for language codes, which are the only subdirs we expect to
  25. # find in po/ anyway. If you put anything else there, you need to suffer
  26. # the consequences of your actions, so we don't do sanity checks
  27. langs=""
  28. for lang in * ; do
  29. if test ! -d $lang; then
  30. continue
  31. fi
  32. langs="$langs $lang"
  33. done
  34. # go back
  35. cd ..
  36. # First thing first, update the .pot template. We place it in the po/
  37. # directory at the top level. You a recent enough xgettext that supports
  38. # --package-name
  39. potfile=po/luanti.pot
  40. echo "updating pot"
  41. xgettext --package-name=luanti \
  42. --add-comments='~' \
  43. --sort-by-file \
  44. --add-location=file \
  45. --keyword=N_ \
  46. --keyword=wgettext \
  47. --keyword=fwgettext \
  48. --keyword=fgettext \
  49. --keyword=fgettext_ne \
  50. --keyword=hgettext \
  51. --keyword=strgettext \
  52. --keyword=wstrgettext \
  53. --keyword=core.gettext \
  54. --keyword=showTranslatedStatusText \
  55. --keyword=fmtgettext \
  56. --output $potfile \
  57. --from-code=utf-8 \
  58. `find src/ -name '*.cpp' -o -name '*.h'` \
  59. `find builtin/ -name '*.lua'`
  60. # Gettext collects a huge amount of bogus comments for the string
  61. # "Available commands: ", and this not once but twice!
  62. # I couldn't figure out how to avoid that so get rid of them afterwards:
  63. for i in 1 2; do
  64. sed '/^#\. ~= 0\.3$/,/^#: /{ /^#: /!d; }' -i $potfile
  65. done
  66. # Now iterate on all languages and create the po file if missing, or update it
  67. # if it exists already
  68. for lang in $langs ; do # note the missing quotes around $langs
  69. pofile=po/$lang/luanti.po
  70. if test -e $pofile; then
  71. echo "[$lang]: updating strings"
  72. msgmerge --update --sort-by-file $pofile $potfile
  73. else
  74. # This will ask for the translator identity
  75. echo "[$lang]: NEW strings"
  76. msginit --locale=$lang --output-file=$pofile --input=$potfile
  77. fi
  78. done