Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect User's Preferred Language and Google Translate Automatically

I use this script in my site for translation

<div id="google_translate_element" align="center"></div>  
<script type="text/javascript">
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({
        pageLanguage: 'auto',
        autoDisplay: false,
        layout: google.translate.TranslateElement.InlineLayout.SIMPLE
        }, 'google_translate_element');
    }
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

It is working just fine :) But is there a way to detect the user ip and auto translate when a user go in to my site?

like image 635
Petar Stoyanov Avatar asked Feb 11 '13 23:02

Petar Stoyanov


People also ask

Can Google Translate automatic language detection?

Starting today, Google Translate's camera can automatically detect languages so you can point your camera at a flyer or sign and get results in your native tongue even if you don't know what language you're reading.

How do I automatically detect a language?

On the Review tab, in the Language group, click Language. Click Set Proofing Language. In the Language dialog box, select the Detect language automatically check box. Review the languages shown above the double line in the Mark selected text as list.

Can Google identify languages?

Google Translate To use it, copy some text in the unknown language and head to Google Translate. Paste your text in the box on the left. As soon as you do, it should detect the language of the pasted text, showing [Language] - Detected above, and translate to English for you.


1 Answers

Although you can use IP-based location detection (see this answer), but it's neither reliable nor makes you wiser about user's preferred languages (e.g. users travelling abroad, etc.).

Websites with heavy international traffic use various parameters to decide in which language the content should be presented. Some of these parameters:

  • Accept-Language HTTP header which is discussed in detail here.
  • Values of properties window.navigator.language or window.navigator.userLanguage (for IE)
  • IP-based location detection data checked against CLDR to provide you with common languages in that territory.

MediaWiki extension, UniversalLanguageSelector, uses these factors as well as stored user preferences to provide a list of common languages for each user. See getFrequentLanguageList().

W3C also has some recommendations.

like image 130
Shervin Avatar answered Oct 31 '22 17:10

Shervin