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.

100 lines
3.5 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. dos2unix "${ORIGINAL_TXT}" &> /dev/null
  18. comment_event=""
  19. comment_node=""
  20. comment_story=""
  21. comment_out=""
  22. out_incr=1
  23. story_first_line=0
  24. while read -r line; do
  25. if [[ ${line} == *"-- [EVENT]"* ]]; then
  26. comment_event="${line}"
  27. elif [[ ${line} == *"+[NODE]"* ]]; then
  28. comment_node="${line}"
  29. elif [[ ${line} == *"[STORY]"* ]]; then
  30. comment_story="${comment_event}@@${comment_node}@@${line}"
  31. #Time for new story, write the comment to pot
  32. echo "#. ${comment_story}" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  33. echo >> "${TEMP_POT}"
  34. story_first_line=1
  35. elif [[ ${line} == *"[/STORY]"* ]]; then
  36. # we reach end of story, write the empty msgid and reinit the comment_story
  37. echo 'msgstr ""' >> "${TEMP_POT}"
  38. echo >> "${TEMP_POT}"
  39. comment_story=""
  40. elif [[ ${line} == *"[OUT]"* ]]; then
  41. comment_out="${comment_event}@@${comment_node}@@[OUT]${out_incr}"
  42. # OUT are one line, let's write it to the pot
  43. echo "#. ${comment_out}" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  44. echo >> "${TEMP_POT}"
  45. # Get rid of special character
  46. line="${line//'"'/'\"'}"
  47. echo "msgid \"${line#\[OUT\]}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  48. echo >> "${TEMP_POT}"
  49. echo 'msgstr ""' >> "${TEMP_POT}"
  50. echo >> "${TEMP_POT}"
  51. ((out_incr++))
  52. elif [[ ${line} == *"[/NODE]"* ]]; then
  53. # We reach end of node, reinit
  54. comment_node=""
  55. comment_story=""
  56. comment_out=""
  57. out_incr=1
  58. elif [[ ${line} == *"[/EVENT]"* ]]; then
  59. # We reach end of event, reinit
  60. comment_event=""
  61. comment_node=""
  62. comment_story=""
  63. comment_out=""
  64. out_incr=1
  65. elif [[ "${comment_story}" != "" && ${story_first_line} == 1 ]]; then
  66. # If the line has nothing particular, and the comment_story is not empty, it's a story string
  67. # Get rid of special character
  68. line="${line//'"'/'\"'}"
  69. # As the story_fist_line is set, it's the first line of the story, add the msgid
  70. echo "msgid \"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  71. echo >> "${TEMP_POT}"
  72. story_first_line=0
  73. elif [[ ${comment_story} != "" ]]; then
  74. # We are on a multilines story, write it but without the msgid
  75. # As developer sometimes forgot empty lines at the end of STORY, skip empty lines
  76. if [[ "${line}" = "" ]]; then
  77. continue
  78. fi
  79. # Get rid of special character
  80. line="${line//'"'/'\"'}"
  81. # Also as this is multiline, we need to add \n to the previous line (no way to detect it sooner...)
  82. sed -e '$s/\(.*\)"$/\1\\n"/' -i "${TEMP_POT}"
  83. echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
  84. echo >> "${TEMP_POT}"
  85. else
  86. # It should be a newline, write a newline
  87. # If new case are added later, we need to deal with it manually, do not break the file by writing them
  88. echo "" >> "${TEMP_POT}"
  89. fi
  90. done < "${ORIGINAL_TXT}"
  91. # Unify duplicate due to pot syntax
  92. msguniq --no-wrap "${TEMP_POT}" > "${POT}"