Fixed generateTranslationDiffs to preserve all newline characters
This commit is contained in:
parent
219138f188
commit
19147c1d75
@ -7,45 +7,52 @@
|
|||||||
# $ ./tools/generateTranslationDiffs.sh
|
# $ ./tools/generateTranslationDiffs.sh
|
||||||
#
|
#
|
||||||
#####################
|
#####################
|
||||||
TEMP=temp_file
|
tmp=temp_file
|
||||||
|
|
||||||
cd "rtdata/languages"
|
cd "rtdata/languages"
|
||||||
if [[ $? != 0 ]]; then
|
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
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#First thing, we want to strip default of any "!" and duplicates.
|
# First thing, we want to strip default of any "!" and duplicates.
|
||||||
grep -v '^!' default | sort -Vu > "$TEMP"
|
grep -v '^!' default | sort -Vu > "$tmp"
|
||||||
mv "$TEMP" "default"
|
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 all already-translated files
|
||||||
find . -not -iname "default" -not -iname "LICENSE" -not -iname "README" -not -iname "*.sh" -not -iname ".*" -not -iname "$TEMP" |
|
find . -not -iname "default" -not -iname "LICENSE" -not -iname "README" -not -iname "*.sh" -not -iname ".*" -not -iname "$tmp" |
|
||||||
|
|
||||||
#for every found language file X
|
# For every file found
|
||||||
while read X; do
|
while read x; do
|
||||||
echo "Working on differences for $X"
|
printf "%s\n" "Working on differences for $x"
|
||||||
|
|
||||||
#Start by copying the existing file to a temporary one, after sorting and removing all "!"
|
# 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 > "$TEMP"
|
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
|
# Now to delete the already-translated lines and add them to $tmp
|
||||||
grep -v '^#' default | while read LINE
|
# Find every line that is not a comment
|
||||||
|
grep -v "^#" default | while read -r 'line'
|
||||||
do
|
do
|
||||||
KEY=${LINE%%;*}
|
# Set "key" to be just the key, without the ";human text"
|
||||||
grep -q "^$KEY" "$X"
|
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 ]]
|
if [[ $? != 0 ]]
|
||||||
then
|
then
|
||||||
echo '!'"${LINE}" >> "$TEMP"
|
# then append a "!" to the line and send it to the language file
|
||||||
|
printf "%s\n" "!${line}" >> "$tmp"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
#Replace the old file with the new one, with a section at the end for differences.
|
# Replace the old file with the new one, with a section at the end for differences.
|
||||||
mv "$TEMP" "$X"
|
mv "$tmp" "$x"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Finished generating differences."
|
printf "%s\n" "Finished generating differences."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user