|
|
- #!/bin/bash
-
- # This script is used to extract modules to pot
- # then pass the .pot in poedit to merge duplication
-
- if [[ "$#" -ne 1 ]]; then
- echo "Please passe exactly 1 parameter: the txt module"
- exit 1
-
- fi
-
- ORIGINAL_TXT=$1
- POT="${ORIGINAL_TXT%%.txt}.pot"
-
- # Reinit exiting POT
- echo > "${POT}"
-
- comment_event=""
- comment_node=""
- comment_story=""
- comment_out=""
- out_incr=1
- story_first_line=0
- while read -r line; do
- if [[ ${line} == *"-- [EVENT]"* ]]; then
- comment_event="${line}"
- elif [[ ${line} == *"+[NODE]"* ]]; then
- comment_node="${line}"
- elif [[ ${line} == *"[STORY]"* ]]; then
- comment_story="${comment_event}@@${comment_node}@@${line}"
- #Time for new story, write the comment to pot
- echo "#. ${comment_story}" | tr -d '\r' | tr -d '\n' >> "${POT}"
- echo >> "${POT}"
- story_first_line=1
- elif [[ ${line} == *"[/STORY]"* ]]; then
- # we reach end of story, write the empty msgid and reinit the comment_story
- echo 'msgstr ""' >> "${POT}"
- echo >> "${POT}"
- comment_story=""
- elif [[ ${line} == *"[OUT]"* ]]; then
- comment_out="${comment_event}@@${comment_node}@@[OUT]${out_incr}"
- # OUT are one line, let's write it to the pot
- echo "#. ${comment_out}" | tr -d '\r' | tr -d '\n' >> "${POT}"
- echo >> "${POT}"
- echo "msgid \"${line#\[OUT\]}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
- echo >> "${POT}"
- echo 'msgstr ""' >> "${POT}"
- echo >> "${POT}"
- ((out_incr++))
- elif [[ ${line} == *"[/NODE]"* ]]; then
- # We reach end of node, reinit
- comment_node=""
- comment_story=""
- comment_out=""
- out_incr=1
- elif [[ ${line} == *"[/EVENT]"* ]]; then
- # We reach end of event, reinit
- comment_event=""
- comment_node=""
- comment_story=""
- comment_out=""
- out_incr=1
- elif [[ "${comment_story}" != "" && ${story_first_line} == 1 ]]; then
- # If the line has nothing particular, and the comment_story is not empty, it's a story string
- # As the story_fist_line is set, it's the first line of the story, add the msgid
- echo "msgid \"${line}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
- echo >> "${POT}"
- story_first_line=0
- elif [[ ${comment_story} != "" ]]; then
- # We are on a multilines story, write it but without the msgid
- echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
- echo >> "${POT}"
- else
- # It should be a newline, write a newline
- # If new are added, we need to deal with it, do not break the file by writing them
- echo "" >> "${POT}"
- fi
-
- done < "${ORIGINAL_TXT}"
|