Is there any tool that can only translate comments in code

I have some C ++ source files containing comments in Italian, is there any tool that can only translate comments into English. I tried google translate, it will translate the whole file, and // will also be translated. Thus, pasting from a translation result from Google does not give a valid C ++ source file.

Any ideas?

Thanks.

+4
source share
1 answer

If Google translate translates is good enough, here is a method that will work for C ++ comments ( // ... ), rude 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 
+5
source

Source: https://habr.com/ru/post/1415274/


All Articles