Is there any tool which can translate only comments in the code

c++, comments, translate

Solution

If Google translate translates well enough, here is a method that will work for C++ comments (`// ...`), crude but effective:

Isolate the comments:
sed -e 's|.*//|//|' -e '/\/\//!s|.*||' sourcefile > comments

Remove the comments from the source:
sed 's|//.*||' sourcefile > barecode

Use Google translate on comments.

paste -d '\0' barecode comments > sourcefile

Problem

I have some c++ source files, which contains comments in Italian language, is there any tool which can translate only comments to English language. I have tried Google translate, it will translate the whole file, and the // will be translated too. So, paste from the translation result from Google does not give a valid c++ source file. Any ideas? Thanks.

Original source