简体   繁体   English

如何在 Django 和 python 中使用谷歌翻译 API

[英]How can I use google translation API in Django with python

I am using Django to create a project where I can change the language of website where user can use the page in any language they are comfortable with.我正在使用 Django 创建一个项目,在该项目中我可以更改网站的语言,用户可以使用他们喜欢的任何语言使用页面。 But I am not sure how to implement google translate API in Django can anyone help me.但我不确定如何在 Django 中实现谷歌翻译 API 任何人都可以帮助我。 I know that we can install google translation API using我知道我们可以安装谷歌翻译 API 使用

"$ pip install googletrans" “$ pip 安装 googletrans”

but how can we implement this in Django framework.但是我们如何在 Django 框架中实现这一点。 I am new to python.我是 python 的新手。 Thank you in advance.先感谢您。

there is a pip package which you can import in your templates and there will be google translate button.有一个 pip package 可以导入到您的模板中,并且会有谷歌翻译按钮。 django-google-translate visit this and you will find more information. django-google-translate访问这个,你会发现更多信息。

you can use googletrans library.您可以使用 googletrans 库。 Here I include the library.这里我包括图书馆。 https://pypi.org/project/googletrans/ Here the documentation also availabe. https://pypi.org/project/googletrans/这里也提供文档。 It is easy to use.它很容易使用。

pip install googletran s pip 安装 googletran s

    from googletrans import Translator

    translator = Translator()
    data = await translator.translate('යුනිකෝඩ් ', dest='ec', src='si').text()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM