tools/update_lua_locale_files.sh
changeset 13090 3f3ad415d849
parent 12715 f84849acda02
child 13511 b62b14aa88d4
equal deleted inserted replaced
13089:c9cdbf630447 13090:3f3ad415d849
    28  ../Scripts/Multiplayer/*.lua\
    28  ../Scripts/Multiplayer/*.lua\
    29  ../Maps/*/map.lua"
    29  ../Maps/*/map.lua"
    30 
    30 
    31 cd ../share/hedgewars/Data/Locale;
    31 cd ../share/hedgewars/Data/Locale;
    32 
    32 
       
    33 # Temporary files
       
    34 TEMP_LOC=$(mktemp);
       
    35 TEMP_HEAD=$(mktemp);
       
    36 TEMP_TAIL=$(mktemp);
       
    37 TEMP_LUA=$(mktemp);
       
    38 
    33 # Collect strings
    39 # Collect strings
    34 echo "Step 1: Collect strings";
    40 echo "Step 1: Collect strings";
    35 echo -n "" > __temp_loc;
    41 echo -n "" > $TEMP_LOC;
    36 for F in loc loc_noop;
    42 for F in loc loc_noop;
    37 	do
    43 	do
    38 	grep -F "$F(\"" $LUAFILES | sed 's/")/")\n/g' | sed "s/.*$F(\"/loc(\"/;s/\").*/\")/" | grep loc | sort | uniq >> __temp_loc;
    44 	grep -F "$F(\"" $LUAFILES | sed 's/")/")\n/g' | sed "s/.*$F(\"/loc(\"/;s/\").*/\")/" | grep loc | sort | uniq >> $TEMP_LOC;
    39 done
    45 done
    40 
    46 
    41 # Update locale files
    47 # Update locale files
    42 # This step is clunky and inefficient. Improve performance (if you are bored)!
    48 # This step is clunky and inefficient. Improve performance (if you are bored)!
    43 echo "Step 2: Update locale files (this may take a while)";
    49 echo "Step 2: Update locale files (this may take a while)";
    44 for i in $LOCALEFILES;
    50 for i in $LOCALEFILES;
    45 do
    51 do
    46 	echo $i;
    52 	echo $i;
    47 	cat __temp_loc | while read f
    53 	cat $TEMP_LOC | while read f
    48 		do
    54 		do
    49 		STR=$(echo "$f" | sed 's/loc("//;s/")\s*$//;s/"/\\"/g');
    55 		STR=$(echo "$f" | sed 's/loc("//;s/")\s*$//;s/"/\\"/g');
    50 		MAPS=$(grep -F -l -- "loc(\"${STR}\")" $LUAFILES | sed 's/.*\/\([^\/]*\)\/map.lua/\1/;s/.*Campaign\/\([^\/]*\)\//\1:/;s/.*\///;s/.lua//;s/ /_/g' | xargs | sed 's/ /, /g');
    56 		MAPS=$(grep -F -l -- "loc(\"${STR}\")" $LUAFILES | sed 's/.*\/\([^\/]*\)\/map.lua/\1/;s/.*Campaign\/\([^\/]*\)\//\1:/;s/.*\///;s/.lua//;s/ /_/g' | xargs | sed 's/ /, /g');
    51 		C=$(echo $MAPS | sed 's/,/\n/' | wc -l)
    57 		C=$(echo $MAPS | sed 's/,/\n/' | wc -l)
    52 		grep -Fq -- "[\"${STR}\"]" $i;
    58 		grep -Fq -- "[\"${STR}\"]" $i;
    65 # Sort
    71 # Sort
    66 echo "Step 3: Sort strings";
    72 echo "Step 3: Sort strings";
    67 for i in $LOCALEFILES;
    73 for i in $LOCALEFILES;
    68 do
    74 do
    69 	echo $i;
    75 	echo $i;
    70 	rm -f __temp_head __temp_tail __temp_lua;
    76 	rm -f $TEMP_HEAD $TEMP_TAIL $TEMP_LUA;
    71 	cat $i | grep -Ev "}|{" | grep -Ev "^[[:space:]]*$" | sort | uniq > __temp_lua;
    77 	cat $i | grep -Ev "}|{" | grep -Ev "^[[:space:]]*$" | sort | uniq > $TEMP_LUA;
    72 	echo "locale = {" > __temp_head;
    78 	echo "locale = {" > $TEMP_HEAD;
    73 	echo "}" > __temp_tail;
    79 	echo "}" > $TEMP_TAIL;
    74 	cat __temp_head __temp_lua __temp_tail > $i;
    80 	cat $TEMP_HEAD $TEMP_LUA $TEMP_TAIL > $i;
    75 done
    81 done
    76 
    82 
    77 # Drop unused
    83 # Drop unused
    78 echo "Step 4: Delete unused strings";
    84 echo "Step 4: Delete unused strings";
    79 cat stub.lua | grep '"] =' | while read f;
    85 cat stub.lua | grep '"] =' | while read f;
    80 do
    86 do
    81 	PHRASE=$(echo "$f" | sed 's/[^[]*\["//;s/"] =.*//;s/"/\\"/g');
    87 	PHRASE=$(echo "$f" | sed 's/[^[]*\["//;s/"] =.*//;s/"/\\"/g');
    82 	CNT=$(grep -Frc "loc(\"$PHRASE\")" __temp_loc);
    88 	CNT=$(grep -Frc "loc(\"$PHRASE\")" $TEMP_LOC);
    83 	if (($CNT==0));
    89 	if (($CNT==0));
    84 	then
    90 	then
    85 		echo "|$PHRASE|";
    91 		echo "|$PHRASE|";
    86 		PHRASE=$(echo "$PHRASE" | sed 's/\\/\\\\/g;s/\[/\\[/g;s/\]/\\]/g;s/\//\\\//g');
    92 		PHRASE=$(echo "$PHRASE" | sed 's/\\/\\\\/g;s/\[/\\[/g;s/\]/\\]/g;s/\//\\\//g');
    87 		sed -i "/.*\[\"$PHRASE\"\].*/d" $LOCALEFILES;
    93 		sed -i "/.*\[\"$PHRASE\"\].*/d" $LOCALEFILES;
    88 	fi;
    94 	fi;
    89 done
    95 done
    90 
    96 
    91 # Delete temporary files
    97 # Delete temporary files
    92 rm __temp_head __temp_tail __temp_lua __temp_loc;
    98 rm $TEMP_HEAD $TEMP_TAIL $TEMP_LUA $TEMP_LOC;
    93 
    99 
    94 echo "Done."
   100 echo "Done."