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.

85 lines
2.9 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 pass exactly 1 parameter: the txt module"
  6. exit 1
  7. fi
  8. ORIGINAL_TXT="$1"
  9. POT_DIR="$(pwd)/Modules/pot/"
  10. POT=$(basename "${ORIGINAL_TXT%%.txt}.pot")
  11. POT="${POT_DIR}/${POT}"
  12. # Reinit exiting POT
  13. mkdir -p "${POT_DIR}"
  14. truncate -s 0 "${POT}"
  15. # First thing first, let's anonymize the pot and delete all email references
  16. sed -i 's/[A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\+\.[A-Za-z]\{2,6\}//' "${POT}"
  17. comment_event=""
  18. comment_node=""
  19. comment_story=""
  20. comment_out=""
  21. out_incr=1
  22. story_first_line=0
  23. while read -r line; do
  24. if [[ ${line} == *"-- [EVENT]"* ]]; then
  25. comment_event="${line}"
  26. elif [[ ${line} == *"+[NODE]"* ]]; then
  27. comment_node="${line}"
  28. elif [[ ${line} == *"[STORY]"* ]]; then
  29. comment_story="${comment_event}@@${comment_node}@@${line}"
  30. #Time for new story, write the comment to pot
  31. echo "#. ${comment_story}" | tr -d '\r' | tr -d '\n' >> "${POT}"
  32. echo >> "${POT}"
  33. story_first_line=1
  34. elif [[ ${line} == *"[/STORY]"* ]]; then
  35. # we reach end of story, write the empty msgid and reinit the comment_story
  36. echo 'msgstr ""' >> "${POT}"
  37. echo >> "${POT}"
  38. comment_story=""
  39. elif [[ ${line} == *"[OUT]"* ]]; then
  40. comment_out="${comment_event}@@${comment_node}@@[OUT]${out_incr}"
  41. # OUT are one line, let's write it to the pot
  42. echo "#. ${comment_out}" | tr -d '\r' | tr -d '\n' >> "${POT}"
  43. echo >> "${POT}"
  44. echo "msgid \"${line#\[OUT\]}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
  45. echo >> "${POT}"
  46. echo 'msgstr ""' >> "${POT}"
  47. echo >> "${POT}"
  48. ((out_incr++))
  49. elif [[ ${line} == *"[/NODE]"* ]]; then
  50. # We reach end of node, reinit
  51. comment_node=""
  52. comment_story=""
  53. comment_out=""
  54. out_incr=1
  55. elif [[ ${line} == *"[/EVENT]"* ]]; then
  56. # We reach end of event, reinit
  57. comment_event=""
  58. comment_node=""
  59. comment_story=""
  60. comment_out=""
  61. out_incr=1
  62. elif [[ "${comment_story}" != "" && ${story_first_line} == 1 ]]; then
  63. # If the line has nothing particular, and the comment_story is not empty, it's a story string
  64. # As the story_fist_line is set, it's the first line of the story, add the msgid
  65. echo "msgid \"${line}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
  66. echo >> "${POT}"
  67. story_first_line=0
  68. elif [[ ${comment_story} != "" ]]; then
  69. # We are on a multilines story, write it but without the msgid
  70. echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
  71. echo >> "${POT}"
  72. else
  73. # It should be a newline, write a newline
  74. # If new are added, we need to deal with it, do not break the file by writing them
  75. echo "" >> "${POT}"
  76. fi
  77. done < "${ORIGINAL_TXT}"