翻译用另一种口语编写的代码注释

发布于 2024-09-06 14:38:21 字数 183 浏览 3 评论 0原文

我刚刚从一位德国程序员那里继承了一些 C 代码,所有注释自然都是德语的。由于我已经忘记了大部分高中德语,所以这是一个小问题。

有谁知道有代码感知的翻译工具吗?这意味着它只会翻译评论中的语言?该项目有很多文件,能够同时对所有文件进行操作也很棒。

我目前正在复制并粘贴到谷歌翻译中,虽然这不太理想,但它至少可以给我一些答案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听你说爱我 2024-09-13 14:38:21

我只知道如何在 java 中执行此操作,但我确信在 C 中也有一种方法可以执行此操作,因为工具存在:

  1. 获取一个能够理解 C 源文件的解析器 (这个 听起来不错,但我不太了解 C)
  2. 构建语法树。迭代树的所有节点,用翻译后的文本替换所有注释节点的文本。
  3. 将树写回新的源文件(可能在不同的目录中)。

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).
煮酒 2024-09-13 14:38:21

从广义上讲,这应该可以使用 Google 翻译的 Ajax API 和一个可以处理回调的正则表达式函数 - 我不认为 JS 的内置正则表达式函数能够胜任这项任务,但我确信那里有库。您必须构建一个正则表达式来隔离注释,将每个块发送到 API,并在回调函数中返回翻译结果。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文