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.

94 lines
3.3 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. TEMP_DIR="$(mktemp -d)"
  11. POT=$(basename "${ORIGINAL_TXT%%.txt}.pot")
  12. TEMP_POT="${TEMP_DIR}/${POT}"
  13. POT="${POT_DIR}/${POT}"
  14. # Reinit exiting POT
  15. mkdir -p "${POT_DIR}"
  16. truncate -s 0 "${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' >> "${TEMP_POT}"
  32. echo >> "${TEMP_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 ""' >> "${TEMP_POT}"
  37. echo >> "${TEMP_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' >> "${TEMP_POT}"
  43. echo >> "${TEMP_POT}"
  44. # Get rid of special character
  45. line="${line//'"'/'\"'}"
  46. echo "msgid \"${line#\[OUT\]}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  47. echo >> "${TEMP_POT}"
  48. echo 'msgstr ""' >> "${TEMP_POT}"
  49. echo >> "${TEMP_POT}"
  50. ((out_incr++))
  51. elif [[ ${line} == *"[/NODE]"* ]]; then
  52. # We reach end of node, reinit
  53. comment_node=""
  54. comment_story=""
  55. comment_out=""
  56. out_incr=1
  57. elif [[ ${line} == *"[/EVENT]"* ]]; then
  58. # We reach end of event, reinit
  59. comment_event=""
  60. comment_node=""
  61. comment_story=""
  62. comment_out=""
  63. out_incr=1
  64. elif [[ "${comment_story}" != "" && ${story_first_line} == 1 ]]; then
  65. # Get rid of special character
  66. line="${line//'"'/'\"'}"
  67. # If the line has nothing particular, and the comment_story is not empty, it's a story string
  68. # As the story_fist_line is set, it's the first line of the story, add the msgid
  69. echo "msgid \"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  70. echo >> "${TEMP_POT}"
  71. story_first_line=0
  72. elif [[ ${comment_story} != "" ]]; then
  73. # Get rid of special character
  74. line="${line//'"'/'\"'}"
  75. # We are on a multilines story, write it but without the msgid
  76. # Also as this is multiline, we need to add \n to the previous line (no way to detect it sooner...)
  77. sed -e '$s/\(.*\)"$/\1\\n"/' -i "${POT}"
  78. echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  79. echo >> "${TEMP_POT}"
  80. else
  81. # It should be a newline, write a newline
  82. # If new are added, we need to deal with it, do not break the file by writing them
  83. echo "" >> "${TEMP_POT}"
  84. fi
  85. done < "${ORIGINAL_TXT}"
  86. # Unify duplicate due to pot syntax
  87. msguniq --no-wrap "${TEMP_POT}" > "${POT}"