Browse Source

Add some more comments to clarify the code, and solve the bug that break newline when txt has space in its name

LecygneNoir 9 months ago
parent
commit
0848957f19
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      extract_module.sh

+ 10
- 4
extract_module.sh View File

@@ -20,13 +20,15 @@ POT="${POT_DIR}/${POT}"
20 20
 mkdir -p "${POT_DIR}"
21 21
 truncate -s 0 "${POT}"
22 22
 
23
+dos2unix "${ORIGINAL_TXT}" &> /dev/null
24
+
23 25
 comment_event=""
24 26
 comment_node=""
25 27
 comment_story=""
26 28
 comment_out=""
27 29
 out_incr=1
28 30
 story_first_line=0
29
-while read -r line; do 
31
+while read -r line; do
30 32
     if  [[ ${line} == *"-- [EVENT]"* ]]; then
31 33
         comment_event="${line}"
32 34
     elif [[ ${line} == *"+[NODE]"* ]]; then
@@ -68,24 +70,28 @@ while read -r line; do
68 70
         comment_out=""
69 71
         out_incr=1
70 72
     elif [[ "${comment_story}" != "" && ${story_first_line} == 1 ]]; then
73
+        # If the line has nothing particular, and the comment_story is not empty, it's a story string
71 74
         # Get rid of special character
72 75
         line="${line//'"'/'\"'}"
73
-        # If the line has nothing particular, and the comment_story is not empty, it's a story string
74 76
         # As the story_fist_line is set, it's the first line of the story, add the msgid
75 77
         echo "msgid \"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
76 78
         echo >> "${TEMP_POT}"
77 79
         story_first_line=0
78 80
     elif [[ ${comment_story} != "" ]]; then
81
+        # We are on a multilines story, write it but without the msgid
82
+        # As developer sometimes forgot empty lines at the end of STORY, skip empty lines
83
+        if [[ "${line}" = "" ]]; then
84
+            continue
85
+        fi
79 86
         # Get rid of special character
80 87
         line="${line//'"'/'\"'}"
81
-        # We are on a multilines story, write it but without the msgid
82 88
         # Also as this is multiline, we need to add \n to the previous line (no way to detect it sooner...)
83 89
         sed -e '$s/\(.*\)"$/\1\\n"/' -i "${TEMP_POT}"
84 90
         echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
85 91
         echo >> "${TEMP_POT}"
86 92
     else
87 93
         # It should be a newline, write a newline
88
-        # If new are added, we need to deal with it, do not break the file by writing them 
94
+        # If new case are added later, we need to deal with it manually, do not break the file by writing them
89 95
         echo "" >> "${TEMP_POT}"
90 96
     fi
91 97
 

Loading…
Cancel
Save