updatepot.sh 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. #
  3. # Update/create voxelands po and pot files
  4. #
  5. # To update only the pot file, execute this script with `./updatepot.sh`.
  6. # You should do this with each modification, addition, or deletion of a
  7. # translatable string in the source code, to give translators the most amount
  8. # of time possible to translate it before the next release. (Transifex
  9. # automatically pulls that file)
  10. #
  11. # To update the pot file and source texts in the po files, execute this script
  12. # with `./updatepot.sh --po`. Though so long as we use Transifex, we shouldn't
  13. # need to use this option.
  14. #
  15. # To start a localization for a new language, create a directory for it in po/
  16. # named as it's language code, then execute this script with
  17. # `./updatepot.sh --po`. But again, as long as we use Transifex, we shouldn't
  18. # need to use this option.
  19. #
  20. # In the above examples, I execute this script from the current directory,
  21. # however it can actually be executed from any directory.
  22. #
  23. # Because we use the --package-name flag, you must have xgettext>=0.17 for
  24. # this script to work. Use `xgettext -V` to check which version you have.
  25. #
  26. # an auxiliary function to abort processing with an optional error message
  27. abort() {
  28. test -n "$1" && echo >&2 "$1"
  29. exit 1
  30. }
  31. # If flags exist, and are written incorrectly, abort.
  32. # Because this is currently the only flag available, I simply used a couple
  33. # if statements to make it work. However in the future, if we want more
  34. # options, we may need to switch to something more advanced, like getopt.
  35. if [[ -n $1 ]] && [[ ! $1 == "--po" ]]; then
  36. abort "'$1' is not a valid option"
  37. fi
  38. # The po/ directory is assumed to be parallel to the directory where
  39. # this script is. Relative paths are fine for us so we can just
  40. # use the following trick (works both for manual invocations and for
  41. # script found from PATH)
  42. scriptisin="$(dirname "$(which "$0")")"
  43. # Commands below are executed from the parent of po/, which is also the
  44. # parent of this script's directory and of the src/ directory.
  45. # We go through $scriptisin so that this script can be executed from whatever
  46. # directory and still work correctly
  47. cd "$scriptisin/.."
  48. test -e po || abort "po/ directory not found"
  49. test -d po || abort "po/ should be a directory, but is not!"
  50. # Create a list of the languages we have to update/create.
  51. # This assumes that we won't have dirnames with spaces, which is
  52. # the case for language codes, which are the only subdirs we expect to
  53. # find in po/ anyway. If you put anything else there, you need to suffer
  54. # the consequences of your actions, so we don't do sanity checks
  55. cd po || abort "couldn't change directory to po!"
  56. langs=""
  57. for lang in * ; do
  58. if test ! -d $lang; then
  59. continue
  60. fi
  61. langs="$langs $lang"
  62. done
  63. # First thing first, update the .pot template. We place it in the po/
  64. # directory at the top level.
  65. echo "updating the pot file"
  66. # go to parent dir of po/ and src/
  67. cd ..
  68. potfile=po/voxelands.pot
  69. xgettext --package-name=voxelands --copyright-holder="Lisa 'darkrose' Milne" -kN_ -kwgettext -F -n -o $potfile src/*.cpp src/*.h
  70. # We just updated the pot file, now update po files if --po was specified.
  71. if [[ $1 == "--po" ]]; then
  72. # Now iterate on all language dirs in po/ and create the po file if
  73. # nonexistent, or update it if it exists already
  74. for lang in $langs ; do # note the missing quotes around $langs
  75. pofile=po/$lang/voxelands.po
  76. if test -e $pofile; then
  77. echo "[$lang]: updating strings"
  78. msgmerge -F -U $pofile $potfile
  79. else
  80. # This creates a new po file and asks for the translator's identity
  81. echo "[$lang]: creating $lang localization files"
  82. msginit -l $lang -o $pofile -i $potfile
  83. fi
  84. done
  85. fi