Python - 英语翻译器
用 Python 编写程序将英语单词和/或短语翻译成其他语言的最佳方法是什么?
What is the best way to approach writing a program in Python to translate English words and/or phrases into other languages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
AJAX Language API
这是一个极其困难的问题 --语言非常非常非常复杂。想想你必须做的所有事情——解析这个短语,弄清楚这些词的意思,然后翻译它们。这可能不惯用,因此您需要针对不同语法的特殊情况。很多很多特殊情况。如果外语与英语不同,你就需要弄清楚它的语法——例如,西班牙语中的“the big green ball”变成了“the ball big green”。
不要重新发明轮子。谷歌为他们的翻译服务提供了一个API,这无疑让许多聪明的人认真思考了这一点。
AJAX Language API
This is an incredibly difficult problem -- language is very very very complicated. Think about all the things you'd have to do -- parse the phrase, work out what the words mean, translate them. That's probably not idiomatic so you'll need special cases for different syntaxes. Many, many special cases. You'll need to work out the syntax of the foreign language if it differs from English -- "the big green ball" goes to "the ball big green" in Spanish, for instance.
Don't reinvent the wheel. Google provide an API to their translation service, which has undoubtedly had many many clever people thinking really quite hard about it.
我认为你应该研究一下 Google Translate API。 这里是一个专门用 python 实现此目的的库。
I think you should look into the Google Translate API. Here is a library implemented specifically for this purpose in python.
最简单的方法是制作一本字典,将一种语言的单词与另一种语言的单词相匹配。然而,这是非常愚蠢的,根本不考虑语法,并且创建翻译器实际上需要很长时间,特别是如果您计划将其用于多种语言。如果语法对您来说并不重要(例如,如果您正在为游戏或故事创建自己的语言,而该语言的语法与英语没有不同),那么您可以使用字典并简单地让函数查找所请求的内容。字典中匹配
the simplest way to do this is to make a dictionary that matches one language's words to another language's words. However, this is extremely silly and would not take into account grammar at all and it would literally take a very long time to create a translator, especially if you plan to use it for multiple languages. If grammar is not important to you (for example, if you were creating your own language for a game or story that doesn't have grammar different from english) than you could get away with using dictionaries and simply having a function look for a requested match in the dictionary
您可以使用 Goslate 包
它非常容易使用
现在的示例
第一个参数是您要翻译的文本,第二个参数是您要翻译的语言。
我希望你会发现这个答案有用
You can use Goslate Package for that
its very easy to use
example
now first argument is text you want to translate and second argument is in which language you want to translate.
i hope you will find the answer usefull
如果您使用深度翻译器,这非常非常容易!这是源代码(确保安装深度翻译模块):
It's very very easy if you use deep-translator! Here's the source code(make sure to install deep-translator module):