需要使用google翻译API翻译xml文件内容
我需要知道如何使用 Google 翻译语言 API 使用 PHP 将 XML 文件的内容从英语翻译成另一种语言,XML 文件中的数据如下所示:
<log>
<titles>
<logfile>Log File</logfile>
<clearlog>Clear Log File</clearlog>
</titles>
</log>
所以我需要将文件传递给 Google API 并在标签之间返回新数据用其他特定语言(例如阿拉伯语):
<log>
<titles>
<logfile>ملف اللوج</logfile>
<clearlog>مسح محتويات الملف</clearlog>
</titles>
</log>
我希望能清楚地表达出来..
谢谢
I need to know how to use Google translate languages API to translate the content of XML file from English to another language using PHP , Data in XML file shown as following:
<log>
<titles>
<logfile>Log File</logfile>
<clearlog>Clear Log File</clearlog>
</titles>
</log>
So i need to pass the file to Google API and return new data between tags in other specific language like in Arabic:
<log>
<titles>
<logfile>ملف اللوج</logfile>
<clearlog>مسح محتويات الملف</clearlog>
</titles>
</log>
I hope that will be clear..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
GTranslate
这是 Google Translate API 的包装器,可以简化您的工作。这是一个示例代码:请注意,Google 限制每个 IP 每天的 API 请求,因此对于具有许多标签的大型 XML 来说,这可能不起作用,或者您可以将整个 XML(带标签)传递给 Google Translate(有 100000字符数也有限制,但这对于很多事情来说已经足够了),然后从翻译结果中提取翻译后的内部文本。
You can use
GTranslate
which is a wrapper for Google Translate API to ease your work. Here is a sample code:note that Google limits API requests per day for each IP, so for a large XML with many tags this may not work, alternatively you can pass the whole XML (with tags) to Google Translate (there is a 100000 characters limit in this too, but that would be enough for many things) and then extract translated inner texts from the translation result.
mkTranslation 可以将 .txt 文件、.string 文件和 .xml 文件翻译成多种语言。
安装:
$pip install mkTranslation
使用方法:
demo:
默认翻译为google翻译,可以指定其他翻译渠道
代码:https://github.com/mythkiven/mkTranslate
mkTranslation can translates .txt file , .string files and .xml files into multiple languages.
Install:
$pip install mkTranslation
Usage:
demo:
The default translation is google translation, you can specify other translation channels
Code:https://github.com/mythkiven/mkTranslate