Detect user’s language in Open Social applications

<?xml version="1.0" encoding="UTF-8"?>
<Module>
   <ModulePrefs title="Hello World!" description="Hello World" title_url="http://www.hi5.com" author="w3mentor" author_email="w3mentor@w3m.com" author_affiliation="w3mentor" author_location="usa" thumbnail="http://w3mentor.com/Logo.png">
    <Icon>http://w3mentor.com/Logo-16x16.png</Icon>
    <Require feature="opensocial-0.8"/>
  </ModulePrefs>
  <Content type="html"><![CDATA[
Hello World!
<div id="greeting" style="background: red;">
</div>
<script>
// Call the init function onLoad
gadgets.util.registerOnLoadHandler(init);
// function to learn users language and display it.
function init() {
var lang = "Not Known ";
try{
var prefs = new gadgets.Prefs();
lang = prefs.getLang();
if (lang == null)
document.getElementById('greeting').innerHTML = "lang is
null"
else
document.getElementById('greeting').innerHTML = "lang is " + lang;
}catch (e) {
document.getElementById('greeting').innerHTML = "exception";}
}
</script>
]]></Content>
</Module>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.