1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # A script to create and install translations for commands
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. # languages to translate into
  31. language=( fr de )
  32. COMMAND_FILES=src/${PROJECT_NAME}*
  33. function create_translation_files {
  34. for f in $COMMAND_FILES
  35. do
  36. COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
  37. bash --dump-po-strings src/${COMMAND_NAME} | xgettext -L PO -o /tmp/${PROJECT_NAME}_${COMMAND_NAME}.pot -
  38. for lang in "${language[@]}"
  39. do
  40. if [ ! -d locale/${lang} ]; then
  41. mkdir -p locale/${lang}
  42. fi
  43. if [ ! -f locale/${lang}/${COMMAND_NAME}.po ]; then
  44. echo "Creating ${lang} Translation file for ${COMMAND_NAME}..."
  45. msginit -l ${lang} -i /tmp/${PROJECT_NAME}_${COMMAND_NAME}.pot -o locale/${lang}/${COMMAND_NAME}.po
  46. fi
  47. done
  48. rm /tmp/${PROJECT_NAME}_${COMMAND_NAME}.pot
  49. done
  50. }
  51. function install_translations {
  52. for f in $COMMAND_FILES
  53. do
  54. COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
  55. for lang in "${language[@]}"
  56. do
  57. if [ ! -f locale/${lang}/${COMMAND_NAME}.mo ]; then
  58. cp locale/${lang}/${COMMAND_NAME}.mo /usr/share/locale/${lang}/${COMMAND_NAME}.mo
  59. fi
  60. done
  61. done
  62. }
  63. if [[ $1 == "make" ]]; then
  64. create_translation_files
  65. exit 0
  66. fi
  67. if [[ $1 == "install" ]]; then
  68. install_translations
  69. exit 0
  70. fi
  71. exit 1