Browse Source

Fix a incorrect escape for double quote and add post treatment with msguniq to automatically merge duplicate string

master
LecygneNoir 5 years ago
parent
commit
f02f8da1a8
1 changed files with 22 additions and 20 deletions
  1. +22
    -20
      extract_module.sh

+ 22
- 20
extract_module.sh View File

@ -11,16 +11,15 @@ fi
ORIGINAL_TXT="$1"
POT_DIR="$(pwd)/Modules/pot/"
TEMP_DIR="$(mktemp -d)"
POT=$(basename "${ORIGINAL_TXT%%.txt}.pot")
TEMP_POT="${TEMP_DIR}/${POT}"
POT="${POT_DIR}/${POT}"
# Reinit exiting POT
mkdir -p "${POT_DIR}"
truncate -s 0 "${POT}"
# First thing first, let's anonymize the pot and delete all email references
sed -i 's/[A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\+\.[A-Za-z]\{2,6\}//' "${POT}"
comment_event=""
comment_node=""
comment_story=""
@ -35,25 +34,25 @@ while read -r line; do
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}"
echo "#. ${comment_story}" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
echo >> "${TEMP_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}"
echo 'msgstr ""' >> "${TEMP_POT}"
echo >> "${TEMP_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 "#. ${comment_out}" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
echo >> "${TEMP_POT}"
# Get rid of special character
line="${line//'"'/'\\"'}"
echo "msgid \"${line#\[OUT\]}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
echo >> "${POT}"
echo 'msgstr ""' >> "${POT}"
echo >> "${POT}"
line="${line//'"'/'\"'}"
echo "msgid \"${line#\[OUT\]}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
echo >> "${TEMP_POT}"
echo 'msgstr ""' >> "${TEMP_POT}"
echo >> "${TEMP_POT}"
((out_incr++))
elif [[ ${line} == *"[/NODE]"* ]]; then
# We reach end of node, reinit
@ -70,11 +69,11 @@ while read -r line; do
out_incr=1
elif [[ "${comment_story}" != "" && ${story_first_line} == 1 ]]; then
# Get rid of special character
line="${line//'"'/'\\"'}"
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' >> "${POT}"
echo >> "${POT}"
echo "msgid \"${line}\"" | tr -d '\r' | tr -d '\n' >> "${TEMP_POT}"
echo >> "${TEMP_POT}"
story_first_line=0
elif [[ ${comment_story} != "" ]]; then
# Get rid of special character
@ -82,12 +81,15 @@ while read -r line; do
# 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 "${POT}"
echo "\"${line}\"" | tr -d '\r' | tr -d '\n' >> "${POT}"
echo >> "${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
echo "" >> "${POT}"
echo "" >> "${TEMP_POT}"
fi
done < "${ORIGINAL_TXT}"
# Unify duplicate due to pot syntax
msguniq --no-wrap "${TEMP_POT}" > "${POT}"

Loading…
Cancel
Save