Fixed generateTranslationDiffs to preserve all newline characters

This commit is contained in:
DrSlony 2012-04-02 20:52:27 +01:00
parent 219138f188
commit 19147c1d75

View File

@ -7,45 +7,52 @@
# $ ./tools/generateTranslationDiffs.sh
#
#####################
TEMP=temp_file
tmp=temp_file
cd "rtdata/languages"
if [[ $? != 0 ]]; then
echo "You must run this script from the root of the project."
printf "%s\n" "You must run this script from the root of the project."
exit
fi
# First thing, we want to strip default of any "!" and duplicates.
grep -v '^!' default | sort -Vu > "$TEMP"
mv "$TEMP" "default"
grep -v '^!' default | sort -Vu > "$tmp"
mv "$tmp" "default"
echo "Generating differences... this may take a few minutes."
printf "%s\n" "Generating differences... this may take a few minutes."
#Find all language files, excluding non-language files
find . -not -iname "default" -not -iname "LICENSE" -not -iname "README" -not -iname "*.sh" -not -iname ".*" -not -iname "$TEMP" |
# Find all already-translated files
find . -not -iname "default" -not -iname "LICENSE" -not -iname "README" -not -iname "*.sh" -not -iname ".*" -not -iname "$tmp" |
#for every found language file X
while read X; do
echo "Working on differences for $X"
# For every file found
while read x; do
printf "%s\n" "Working on differences for $x"
#Start by copying the existing file to a temporary one, after sorting and removing all "!"
grep -v '^!' "$X" | sort -Vu > "$TEMP"
# Find every already-translated line (every line that does not start with an "!") in file "$x", then sort and copy the file to "$tmp"
grep -v '^!' "$x" | sort -Vu > "$tmp"
echo -e "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!\n! Untranslated keys follow; remove the ! prefix after an entry is translated.\n!!!!!!!!!!!!!!!!!!!!!!!!!\n\n" >> "$TEMP"
printf "%s\n" '' '!!!!!!!!!!!!!!!!!!!!!!!!!' '! Untranslated keys follow; remove the ! prefix after an entry is translated.' '!!!!!!!!!!!!!!!!!!!!!!!!!' '' >> "$tmp"
#find every line that is not a comment
grep -v '^#' default | while read LINE
# Now to delete the already-translated lines and add them to $tmp
# Find every line that is not a comment
grep -v "^#" default | while read -r 'line'
do
KEY=${LINE%%;*}
grep -q "^$KEY" "$X"
# Set "key" to be just the key, without the ";human text"
key="${line%%;*}"
# Scan the translated file $x for a translated $key
grep -q "^$key" "$x"
# If it did not find a translated key in $x,
if [[ $? != 0 ]]
then
echo '!'"${LINE}" >> "$TEMP"
# then append a "!" to the line and send it to the language file
printf "%s\n" "!${line}" >> "$tmp"
fi
done
# Replace the old file with the new one, with a section at the end for differences.
mv "$TEMP" "$X"
mv "$tmp" "$x"
done
echo "Finished generating differences."
printf "%s\n" "Finished generating differences."