From 0848957f19ba739a923de91b6197114cc2c883fc Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Sun, 17 Feb 2019 11:16:58 +0100 Subject: [PATCH] Add some more comments to clarify the code, and solve the bug that break newline when txt has space in its name --- extract_module.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extract_module.sh b/extract_module.sh index 035a49d..7f35bf5 100755 --- a/extract_module.sh +++ b/extract_module.sh @@ -20,13 +20,15 @@ POT="${POT_DIR}/${POT}" mkdir -p "${POT_DIR}" truncate -s 0 "${POT}" +dos2unix "${ORIGINAL_TXT}" &> /dev/null + comment_event="" comment_node="" comment_story="" comment_out="" out_incr=1 story_first_line=0 -while read -r line; do +while read -r line; do if [[ ${line} == *"-- [EVENT]"* ]]; then comment_event="${line}" elif [[ ${line} == *"+[NODE]"* ]]; then @@ -68,24 +70,28 @@ while read -r line; do 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 # Get rid of special character line="${line//'"'/'\"'}" - # 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' >> "${TEMP_POT}" echo >> "${TEMP_POT}" story_first_line=0 elif [[ ${comment_story} != "" ]]; then + # We are on a multilines story, write it but without the msgid + # As developer sometimes forgot empty lines at the end of STORY, skip empty lines + if [[ "${line}" = "" ]]; then + continue + fi # Get rid of special character line="${line//'"'/'\"'}" - # We are on a multilines story, write it but without the msgid # Also as this is multiline, we need to add \n to the previous line (no way to detect it sooner...) sed -e '$s/\(.*\)"$/\1\\n"/' -i "${TEMP_POT}" echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}" echo >> "${TEMP_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 + # If new case are added later, we need to deal with it manually, do not break the file by writing them echo "" >> "${TEMP_POT}" fi