From 9defce2dcb9530e99abe84aca2a1331da9092d5e Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Fri, 1 Nov 2019 12:43:44 +0100 Subject: [PATCH] Add the possibility to manage empty modules in the event .txt files, fix #10 --- README.md | 10 +--------- extract_module.sh | 21 +++++++++++++++++++++ rollback_module.sh | 15 +++++++++++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2af4694..b8a6da8 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,4 @@ To convert back from po: ```bash echo "start at $(date)"; time for i in Translation/fr/po/Modules/*; do echo "rollback ${i}..."; time ./rollback_module.sh "${i}" fr; echo "done"; done; echo "end at $(date)"; -``` - -**Warning** : Empty events are not recreated (as they disappear on .pot), so be careful: - - search for this in the Modules/game_files/*.txt - ```bash --- \[EVENT\].*$ -\[/EVENT\] -``` - - Report all empty events in the corresponding txt in Translation/modules \ No newline at end of file +``` \ No newline at end of file diff --git a/extract_module.sh b/extract_module.sh index 7f35bf5..361e9a4 100755 --- a/extract_module.sh +++ b/extract_module.sh @@ -26,13 +26,18 @@ comment_event="" comment_node="" comment_story="" comment_out="" +event_empty=0 out_incr=1 story_first_line=0 while read -r line; do if [[ ${line} == *"-- [EVENT]"* ]]; then comment_event="${line}" + # At start of event, we set event_empty just in case + event_empty=1 elif [[ ${line} == *"+[NODE]"* ]]; then comment_node="${line}" + # At least one node, disable event_empty + event_empty=0 elif [[ ${line} == *"[STORY]"* ]]; then comment_story="${comment_event}@@${comment_node}@@${line}" #Time for new story, write the comment to pot @@ -62,6 +67,22 @@ while read -r line; do comment_story="" comment_out="" out_incr=1 + elif [[ ${line} == *"[/EVENT]"* && ${event_empty} == 1 ]]; then + # We reach end of event and the event is empty, write special lines + comment_empty="${comment_event}EMPTY@@[EMPTY]0@@[EMPTY]0" + echo "#. ${comment_empty}" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}" + echo >> "${TEMP_POT}" + echo 'msgid "[SPECIAL EMPTY EVENT STRING]"' >> "${TEMP_POT}" + echo >> "${TEMP_POT}" + echo 'msgstr "[SPECIAL EMPTY EVENT STRING]"' >> "${TEMP_POT}" + echo >> "${TEMP_POT}" + # Then reinit + comment_event="" + comment_node="" + comment_story="" + comment_out="" + event_empty=0 + out_incr=1 elif [[ ${line} == *"[/EVENT]"* ]]; then # We reach end of event, reinit comment_event="" diff --git a/rollback_module.sh b/rollback_module.sh index aa8c7ba..ba7abbf 100755 --- a/rollback_module.sh +++ b/rollback_module.sh @@ -75,16 +75,27 @@ function rebuild_txt { currentEvent="" currentNode="" + isEmpty=0 for index in "${sortedEvent[@]}"; do # If currentEvent is different than our index, then we just changed event and need to close the precedent # We also closed the next event in line - if [[ ${currentEvent} != ${index} && "${currentEvent}" != "" ]]; then + if [[ ${currentEvent} != ${index} && "${currentEvent}" != "" && "${isEmpty}" != "1" ]]; then echo "[/NODE]" >> "${TXT}" echo >> "${TXT}" echo "[/EVENT]" >> "${TXT}" echo >> "${TXT}" fi - echo "${eventArray[${index}]}" >> "${TXT}" + echo "${eventArray[${index}]%EMPTY}" >> "${TXT}" + # If the Event contains EMPTY then it's a special empty event, we need to close it without le [/NODE] + # Then we pass directly to the next event + if [[ ${eventArray[${index}]} == *"EMPTY"* ]]; then + echo "[/EVENT]" >> "${TXT}" + echo >> "${TXT}" + isEmpty=1 + currentEvent=${index} + continue + fi + isEmpty=0 for key in "${sorted[@]}"; do # We work only on key related to our current event # We need to compare key to the event id in index, ie the first part of the key (see #7)