123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. if [ ! -d /tmp/${PROJECT_NAME} ]; then
  35. mkdir -p /tmp/${PROJECT_NAME}
  36. fi
  37. for f in $COMMAND_FILES
  38. do
  39. COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
  40. bash --dump-po-strings src/${COMMAND_NAME} | xgettext -L PO -o /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot -
  41. if [ -f /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot ]; then
  42. for lang in "${language[@]}"
  43. do
  44. if [ ! -d locale/${lang} ]; then
  45. mkdir -p locale/${lang}
  46. fi
  47. if [ ! -f locale/${lang}/${COMMAND_NAME}.po ]; then
  48. echo "Creating ${lang} Translation file for ${COMMAND_NAME}..."
  49. msginit -l ${lang} -i /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot -o locale/${lang}/${COMMAND_NAME}.po
  50. fi
  51. done
  52. rm /tmp/${PROJECT_NAME}/${COMMAND_NAME}.pot
  53. fi
  54. done
  55. }
  56. function install_translations {
  57. for f in $COMMAND_FILES
  58. do
  59. COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
  60. for lang in "${language[@]}"
  61. do
  62. if [ -f locale/${lang}/${COMMAND_NAME}.mo ]; then
  63. cp locale/${lang}/${COMMAND_NAME}.mo /usr/share/locale/${lang}/${COMMAND_NAME}.mo
  64. fi
  65. done
  66. done
  67. }
  68. function uninstall_translations {
  69. for f in $COMMAND_FILES
  70. do
  71. COMMAND_NAME=$(echo $f | awk -F '/' '{print $2}')
  72. for lang in "${language[@]}"
  73. do
  74. if [ -f /usr/share/locale/${lang}/${COMMAND_NAME}.mo ]; then
  75. rm /usr/share/locale/${lang}/${COMMAND_NAME}.mo
  76. fi
  77. done
  78. done
  79. }
  80. if [[ $1 == "make" ]]; then
  81. create_translation_files
  82. exit 0
  83. fi
  84. if [[ $1 == "install" ]]; then
  85. install_translations
  86. exit 0
  87. fi
  88. if [[ $1 == "uninstall" ]]; then
  89. uninstall_translations
  90. exit 0
  91. fi
  92. exit 1