瀏覽代碼

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

master
LecygneNoir 5 年之前
父節點
當前提交
0848957f19
共有 1 個文件被更改,包括 10 次插入4 次删除
  1. +10
    -4
      extract_module.sh

+ 10
- 4
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

Loading…
取消
儲存