Is there any tool which can translate only comments in the code [closed]
Asked Answered
S

1

8

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.

Shaughn answered 31/5, 2012 at 1:53 Comment(8)
what's wrong with Italic? Its a little slanty but easy enough to read :)Correlate
did you mean Italian language? cause I never heard of Italic.Felting
I wonder how many Italian C++ programmers there are that know English well. At least 10,000 I'd say. You only need one.Gunter
Sorry about my original question, I mean there are many comments which in Italian language. I would like to translate those comments in English language. I have update my original question.Shaughn
You'll have to write a small script to extract comments, translate them, then search & replace the originals.Hipped
A couple points: first, to translate comments well, the translator probably needs to be a programmer. Second, it's probably better to leave the comments in the source code, so he can refer to the code for context in case of confusion (I've certain written a fair number of comments that would be nearly meaningless without the code surrounding them).Fossorial
Agree with the need for a skilled translator. I've seen exit being translated as Ausfahrt in german (which is a highway exit/offramp)Oblique
@MSalters: which isn't such a bad translation in a software context.Twentyfour
T
5

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
Twentyfour answered 1/6, 2012 at 3:14 Comment(2)
I am trying to convert from Chinese to English comments, but in google translate getting error as Sorry, the page you requested contains a file type (application/octet-stream) we are unable to translate.Albania
I found github.com/riversun/JavaCommentTranslator which claims to handle C as wellTempletempler

© 2022 - 2024 — McMap. All rights reserved.