tools/check_engine_locale_files.sh
changeset 13965 fa9b22311390
child 13967 a04c86dc685f
equal deleted inserted replaced
13964:fc43d63ee5a7 13965:fa9b22311390
       
     1 #!/bin/sh -
       
     2 # Script to check all engine locale files (XX.txt)
       
     3 
       
     4 # HOW TO USE:
       
     5 # - Run this script in the tools/ directory.
       
     6 # Result: All problems and missing translations in .txt files will be reported
       
     7 
       
     8 # SYNTAX:
       
     9 #
       
    10 #     ./check_engine_locale_files.sh [file_to_check [show_untranslated]]
       
    11 #
       
    12 # Optional parameters:
       
    13 #
       
    14 # * file_to_check: Add this if you want to check a single file. Use the special value ALL to check all files.
       
    15 # * show_untranslated: Set to 0 if you want to hide the list of untranslated files, set to 1 otherwise
       
    16 
       
    17 SHOW_UNTRANSLATED_STRINGS=1;
       
    18 CHECKED_FILES=*.txt
       
    19 
       
    20 # Parse command line
       
    21 if [[ $# -gt 0 ]]
       
    22 then
       
    23 	if [ $1 = ALL ]
       
    24 	then
       
    25 		CHECKED_FILES=*.txt
       
    26 	else
       
    27 		CHECKED_FILES=$1;
       
    28 	fi
       
    29 fi
       
    30 if [[ $# -gt 1 ]]
       
    31 then
       
    32 	if [[ $2 -eq 1 ]]
       
    33 	then
       
    34 		SHOW_UNTRANSLATED_STRINGS=1;
       
    35 	elif [[ $2 -eq 0 ]]
       
    36 	then
       
    37 		SHOW_UNTRANSLATED_STRINGS=0;
       
    38 	fi
       
    39 fi
       
    40 
       
    41 cd ../share/hedgewars/Data/Locale;
       
    42 
       
    43 # Temporary files
       
    44 TEMP_SYMBOLS_EN=$(mktemp);
       
    45 TEMP_SYMBOLS=$(mktemp);
       
    46 TEMP_COMPARE=$(mktemp);
       
    47 TEMP_COMPARE_2=$(mktemp);
       
    48 TEMP_CHECK=$(mktemp);
       
    49 TEMP_TEMP=$(mktemp);
       
    50 declare -a TEMP_PARAMS;
       
    51 for n in 0 1 2 3 4 5 6 7 8 9
       
    52 do
       
    53 	TEMP_PARAMS[$n]=$(mktemp);
       
    54 done
       
    55 
       
    56 # Collect list of string IDs
       
    57 echo -n "" > $TEMP_SYMBOLS_EN;
       
    58 grep -o "^[0-9][0-9]:[0-9][0-9]=" en.txt | cut -c1-5 | sort | uniq > $TEMP_SYMBOLS_EN;
       
    59 TOTAL_STRINGS=`wc -l < $TEMP_SYMBOLS_EN`;
       
    60 
       
    61 # Collect strings with placeholders (only in 01:XX)
       
    62 for n in 0 1 2 3 4 5 6 7 8 9
       
    63 do
       
    64 	grep -o "^01:[0-9][0-9]=.*%$n.*" en.txt | cut -c1-5 | sort | uniq > $TEMP_PARAMS[$n];
       
    65 done
       
    66 
       
    67 # Iterate through selected language files
       
    68 for CHECKED_LANG_FILE in $CHECKED_FILES;
       
    69 	# Skip files that don't contain engine strings
       
    70 	do
       
    71 	if [[ $CHECKED_LANG_FILE == campaigns_* ]] || [[ $CHECKED_LANG_FILE == missions_* ]] || [ $CHECKED_LANG_FILE == CMakeLists.txt ]
       
    72 	then
       
    73 		continue;
       
    74 	fi
       
    75 	if [ ! -e $CHECKED_LANG_FILE ]
       
    76 	then
       
    77 		echo "ERROR: $CHECKED_LANG_FILE not found!";
       
    78 		continue;
       
    79 	fi
       
    80 	if [ ! -r $CHECKED_LANG_FILE ]
       
    81 	then
       
    82 		echo "ERROR: No permission to read $CHECKED_LANG_FILE!";
       
    83 		continue;
       
    84 	fi
       
    85 
       
    86 	# Start the tests
       
    87 	echo "== $CHECKED_LANG_FILE ==";
       
    88 	MISSING_STRINGS=0;
       
    89 	HAS_PROBLEMS=0;
       
    90 
       
    91 	# Find duplicate placeholders
       
    92 	for i in 0 1 2 3 4 5 6 7 8 9
       
    93 	do
       
    94 		grep -G "%$i.*%$i" $CHECKED_LANG_FILE > $TEMP_CHECK;
       
    95 		if [ -s $TEMP_CHECK ]
       
    96 		then
       
    97 			echo "ERROR! Duplicate placeholders found:";
       
    98 			cat $TEMP_CHECK;
       
    99 			HAS_PROBLEMS=1;
       
   100 		fi
       
   101 	done;
       
   102 
       
   103 	if [ $CHECKED_LANG_FILE != en.txt ]
       
   104 	then
       
   105 		grep -o "^[0-9][0-9]:[0-9][0-9]=" $CHECKED_LANG_FILE | cut -c1-5 | sort | uniq > $TEMP_SYMBOLS;
       
   106 
       
   107 		# Find strings with missing placeholders
       
   108 		> $TEMP_COMPARE;
       
   109 		> $TEMP_COMPARE_2;
       
   110 		for n in 0 1 2 3 4 5 6 7 8 9
       
   111 		do
       
   112 			grep -o "^01:[0-9][0-9]=.*%$n.*" $CHECKED_LANG_FILE | cut -c1-5 | sort | uniq > $TEMP_CHECK;
       
   113 			comm $TEMP_PARAMS[$n] $TEMP_CHECK -2 -3 >> $TEMP_COMPARE;
       
   114 			comm $TEMP_PARAMS[$n] $TEMP_CHECK -1 -3 >> $TEMP_COMPARE_2;
       
   115 		done
       
   116 		cat $TEMP_COMPARE | cut -c1-5 | sort | uniq > $TEMP_TEMP;
       
   117 		cat $TEMP_TEMP > $TEMP_COMPARE;
       
   118 		comm $TEMP_COMPARE $TEMP_SYMBOLS -1 -2 > $TEMP_TEMP;
       
   119 		if [ -s $TEMP_TEMP ]
       
   120 		then
       
   121 			echo "ERROR! Missing placeholders in these strings:";
       
   122 			cat $TEMP_TEMP;
       
   123 			HAS_PROBLEMS=1;
       
   124 		fi
       
   125 		cat $TEMP_COMPARE_2 | cut -c1-5 | sort | uniq > $TEMP_TEMP;
       
   126 		cat $TEMP_TEMP > $TEMP_COMPARE_2;
       
   127 		comm $TEMP_COMPARE_2 $TEMP_SYMBOLS -1 -2 > $TEMP_TEMP;
       
   128 		if [ -s $TEMP_TEMP ]
       
   129 		then
       
   130 			echo "ERROR! Invalid placeholders found in these strings:";
       
   131 			cat $TEMP_TEMP;
       
   132 			HAS_PROBLEMS=1;
       
   133 		fi
       
   134 	
       
   135 		# Find superficial strings
       
   136 		comm $TEMP_SYMBOLS_EN $TEMP_SYMBOLS -1 -3 > $TEMP_COMPARE;
       
   137 		if [ -s $TEMP_COMPARE ]
       
   138 		then
       
   139 			echo "WARNING! Superficial strings that do not exist in en.txt:";
       
   140 			cat $TEMP_COMPARE;
       
   141 			HAS_PROBLEMS=1;
       
   142 		fi
       
   143 	
       
   144 		# Find missing translations
       
   145 		comm $TEMP_SYMBOLS_EN $TEMP_SYMBOLS -2 -3 > $TEMP_COMPARE;
       
   146 		if [ -s $TEMP_COMPARE ]
       
   147 		then
       
   148 			if [ $SHOW_UNTRANSLATED_STRINGS -eq 1 ]
       
   149 			then
       
   150 				echo "Missing translations:";
       
   151 				cat $TEMP_COMPARE;
       
   152 			fi
       
   153 			MISSING_STRINGS=`wc -l < $TEMP_COMPARE`;
       
   154 		fi
       
   155 
       
   156 		# Print summary
       
   157 		if [ $MISSING_STRINGS -ne 0 ]
       
   158 		then
       
   159 			echo "Missing translations TOTAL: $MISSING_STRINGS/$TOTAL_STRINGS";
       
   160 		else
       
   161 			echo "All strings translated!";
       
   162 		fi
       
   163 		if [ $HAS_PROBLEMS -eq 1 ]
       
   164 		then
       
   165 			echo "Problems have been found.";
       
   166 		fi
       
   167 	else
       
   168 		if [ $HAS_PROBLEMS -eq 0 ]
       
   169 		then
       
   170 			echo "No problems.";
       
   171 		fi
       
   172 	fi;
       
   173 		
       
   174 done;
       
   175 
       
   176 # Clean up files
       
   177 rm $TEMP_SYMBOLS $TEMP_SYMBOLS_EN $TEMP_COMPARE $TEMP_COMPARE_2 $TEMP_CHECK $TEMP_TEMP;