views:

44

answers:

2

I've just inherited some C code from a German programmer, and all of the comments are, naturally, in German. As I've forgotten most of my high school German, this is a slight problem.

Does anyone know of any translation tools that are code-aware; meaning it will only translate language within comments? The project has many files, being able to operate on all of them at once would also be fantastic.

I'm currently copying-and-pasting into Google Translate, and while this is less than ideal, it can at least get me some answers.

A: 

I would only know exactly how to do this in java, but I am sure there is a way to do this in C as well, as the tools exist:

  1. Grab a parser that understands C source files (this one sounds ok, but I don't know much about C)
  2. build a syntax tree. iterate over all nodes of the tree, replacing the text of all comment nodes with translated text.
  3. write the tree back to a new source file (perhaps in a different directory).
seanizer
A: 

Very broadly, this should be possible to do using Google translation's Ajax API and a regex function that can deal with callbacks - I don't think JS's built-in regex functions are up to the task but I'm sure there are libraries out there. You would have to build a regular expression that can isolate the comments, send each chunk to the API, and return the translated result in the callback function.

Pekka