Auto translating website using Google Translate

不羁的心 提交于 2019-12-21 03:15:34

问题


I need to find a way to translate a website to the appropriate language as the locale settings on a users machine. So in otherwords someone from Germany visits my site, his locale settings are GErman, nou the site displays in German, is this possible to do using Google Translate or are there other options available?


回答1:


I know that when I visit a site in another language using Google Chrome, it says "This site appears to be in [Drop Down With Languages]. Do you want Google to translate it?" They might have an api that can do that per page.

However, if your site is at all professional, you should get someone to actually translate your site for you, as occasionally Google translate fails in embarrassing ways.




回答2:


Use Follwing code in your head tag

<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

display laguage dropdown where you want to display it

<div id="google_translate_element"></div>

If use only some languages translate than use

pageLanguage: 'en',
includedLanguages: 'pt,ar',


来源:https://stackoverflow.com/questions/5033495/auto-translating-website-using-google-translate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!