Scripting tools to interact with Thea 2 The Shattering files in order to translate them easily.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.7 KiB

  1. #!/bin/bash
  2. # This script is used to extract modules to pot
  3. # then pass the .pot in poedit to merge duplication
  4. if [[ "$#" -ne 1 ]]; then
  5. echo "Please passe exactly 1 parameter: the txt module"
  6. exit 1
  7. fi
  8. ORIGINAL_TXT=$1
  9. POT="${ORIGINAL_TXT%%.txt}.pot"
  10. # Reinit exiting POT
  11. echo > "${POT}"
  12. comment_event=""
  13. comment_node=""
  14. comment_story=""
  15. comment_out=""
  16. out_incr=1
  17. story_first_line=0
  18. while read -r line; do
  19. if [[ ${line} == *"-- [EVENT]"* ]]; then
  20. comment_event="${line}"
  21. elif [[ ${line} == *"+[NODE]"* ]]; then
  22. comment_node="${line}"
  23. elif [[ ${line} == *"[STORY]"* ]]; then
  24. comment_story="${comment_event}@@${comment_node}@@${line}"
  25. #Time for new story, write the comment to pot
  26. echo "#. ${comment_story}" | tr -d '\r' | tr -d '\n' >> "${POT}"
  27. echo >> "${POT}"
  28. story_first_line=1
  29. elif [[ ${line} == *"[/STORY]"* ]]; then
  30. # we reach end of story, write the empty msgid and reinit the comment_story
  31. echo 'msgstr ""' >> "${POT}"
  32. echo >> "${POT}"
  33. comment_story=""
  34. elif [[ ${line} == *"[OUT]"* ]]; then
  35. comment_out="${comment_event}@@${comment_node}@@[OUT]${out_incr}"
  36. # OUT are one line, let's write it to the pot
  37. echo "#. ${comment_out}" | tr -d '\r' | tr -d '\n' >> "${POT}"
  38. echo >> "${POT}"
  39. echo "msgid \"${line#\[OUT\]}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
  40. echo >> "${POT}"
  41. echo 'msgstr ""' >> "${POT}"
  42. echo >> "${POT}"
  43. ((out_incr++))
  44. elif [[ ${line} == *"[/NODE]"* ]]; then
  45. # We reach end of node, reinit
  46. comment_node=""
  47. comment_story=""
  48. comment_out=""
  49. out_incr=1
  50. elif [[ ${line} == *"[/EVENT]"* ]]; then
  51. # We reach end of event, reinit
  52. comment_event=""
  53. comment_node=""
  54. comment_story=""
  55. comment_out=""
  56. out_incr=1
  57. elif [[ "${comment_story}" != "" && ${story_first_line} == 1 ]]; then
  58. # If the line has nothing particular, and the comment_story is not empty, it's a story string
  59. # As the story_fist_line is set, it's the first line of the story, add the msgid
  60. echo "msgid \"${line}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
  61. echo >> "${POT}"
  62. story_first_line=0
  63. elif [[ ${comment_story} != "" ]]; then
  64. # We are on a multilines story, write it but without the msgid
  65. echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
  66. echo >> "${POT}"
  67. else
  68. # It should be a newline, write a newline
  69. # If new are added, we need to deal with it, do not break the file by writing them
  70. echo "" >> "${POT}"
  71. fi
  72. done < "${ORIGINAL_TXT}"