Steps to translate the comments of a source file:
- Translate the file in Google Translate or other translation service
- Copy the result of the translation to a new file
- Check that there are no extra or removed lines. If so, align the original and translated files
- Only one-line comments are supported. If there are blocks with C-style comments, preceed the comments in these lines with //
- Execute:
translate_comments.sh original_file translated_file
The script is:
#!/bin/ksh
TMP1=`mktemp`
TMP2=`mktemp`
cat $1 | awk -F"//" '{print $1;}' > $TMP1
cat $2 | awk -F"//" '{if (NF > 1) print "//"$2; else print "";}' > $TMP2
awk -F"//" '{
while ((getline code < ARGV[1]) > 0)
{
getline comment < ARGV[2];
print code""comment;
}
}' $TMP1 $TMP2
rm $TMP1 $TMP2
The script is available for download at:https://github.com/jmgomezpoveda/Tools/tree/master/TranslateComments