From 19147c1d751ba5e6f9d5dcfa6dedf565526de00d Mon Sep 17 00:00:00 2001 From: DrSlony Date: Mon, 2 Apr 2012 20:52:27 +0100 Subject: [PATCH] Fixed generateTranslationDiffs to preserve all newline characters --- tools/generateTranslationDiffs | 55 +++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/tools/generateTranslationDiffs b/tools/generateTranslationDiffs index ad87252fb..58488fe0f 100755 --- a/tools/generateTranslationDiffs +++ b/tools/generateTranslationDiffs @@ -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" +# First thing, we want to strip default of any "!" and duplicates. +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" - - echo -e "\n\n!!!!!!!!!!!!!!!!!!!!!!!!!\n! Untranslated keys follow; remove the ! prefix after an entry is translated.\n!!!!!!!!!!!!!!!!!!!!!!!!!\n\n" >> "$TEMP" - - #find every line that is not a comment - grep -v '^#' default | while read LINE + # 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" + + printf "%s\n" '' '!!!!!!!!!!!!!!!!!!!!!!!!!' '! Untranslated keys follow; remove the ! prefix after an entry is translated.' '!!!!!!!!!!!!!!!!!!!!!!!!!' '' >> "$tmp" + + # 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" + # Replace the old file with the new one, with a section at the end for differences. + mv "$tmp" "$x" done -echo "Finished generating differences." +printf "%s\n" "Finished generating differences."