是否有任何工具只能翻译代码中的注释

时间:2012-05-31 01:53:26

标签: c++ comments translate

我有一些c ++源文件,其中包含意大利语的注释,是否有任何工具只能将注释翻译成英语。我试过谷歌翻译,它将翻译整个文件,//也将被翻译。因此,从Google的翻译结果中粘贴不会提供有效的c ++源文件。

有什么想法吗?

感谢。

1 个答案:

答案 0 :(得分:5)

如果谷歌翻译的翻译得足够好,这里的方法适用于C ++评论(// ...),粗略但有效:

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
相关问题