7

有什么翻译工具或者翻译的 API 可以实现翻译文件里面的中文,保留英文?

 1 year ago
source link: https://www.v2ex.com/t/907315
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  问与答

有什么翻译工具或者翻译的 API 可以实现翻译文件里面的中文,保留英文?

  TonyHoAspire · 3 小时 46 分钟前 · 164 次点击

某个项目里面的代码里面有一部分中文字符串,现在需要这些项目文件里面的中文翻译成英文,其他部分保持不变。 不知道是否有命令行或者可以批量处理的工具不?

因为文件比较多,而且有些代码文件很长,所以手动拖动到某个工具中(例如 DeepL )不方便。

如果有其他的方式,也可以提供信息。多谢。

3 条回复    2023-01-08 12:10:56 +08:00
bjzhush

bjzhush      3 小时 25 分钟前

你自己都没试吧,我花半分钟试了下,google translation 对中英文混合的内容只翻译中文,英文和符号包括格式都不变。
所以理论上来说,google translation API 就可以解决你这个问题,这个 API 每月有 50 万字符的免费翻译额度
TonyHoAspire

TonyHoAspire      2 小时 27 分钟前

@bjzhush 你使用的是网页版吗? 如果你用的是 cli 版本,可以告知一下吗?
我尝试使用 cli 版本(这个 https://github.com/lushan88a/google_trans_new )。
没有跑起来:

Traceback (most recent call last):
File "/home/telink/.local/lib/python3.7/site-packages/google_trans_new/google_trans_new.py", line 189, in translate
r.raise_for_status()
File "/usr/local/python3/lib/python3.7/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError( http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://translate.google.cn/_/TranslateWebserverUi/data/batchexecute

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "tran.py", line 41, in <module>
raise e
File "tran.py", line 38, in <module>
results = pool.map(request, texts)
File "/usr/local/python3/lib/python3.7/multiprocessing/pool.py", line 268, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/local/python3/lib/python3.7/multiprocessing/pool.py", line 657, in get
raise self._value
File "/usr/local/python3/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/usr/local/python3/lib/python3.7/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "tran.py", line 26, in request
translate_text = t.translate(text.strip(), lang)
File "/home/telink/.local/lib/python3.7/site-packages/google_trans_new/google_trans_new.py", line 194, in translate
raise google_new_transError(tts=self, response=r)
google_trans_new.google_trans_new.google_new_transError: 404 (Not Found) from TTS API. Probable cause: Unknown

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK