I need to find a way to translate a website to the appropriate language as the locale set开发者_如何学编程tings 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?
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',
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.
精彩评论