Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > detect language using javascript View modes: 
User avatar
Member
Member
jinijose-gmail - 1/14/2011 4:40:57 AM
   
detect language using javascript
i have added three language to my site.
is it possible to detect the language through javascript ?

User avatar
Member
Member
kentico_michal - 1/14/2011 6:25:05 AM
   
RE:detect language using javascript
Hi,

You can put some literal control into the page (if you are using portal engine, you can put it into some user control that you can put on the page using UserControl web part) and into Text property of this literal you can put (e.g. in Page_Load method) HTML tag input of type hidden and into its value attribute insert the culture code. Please find sample code bellow:

ltlInput = "<input type=\"hidden\" id=\"cultureCode\" name=\"cultureCode\" value=\"" + CMS.CMSHelper.CMSContext.CurrentDocumentCulture + "\" />";

Then the culture code will be not visible on the page, but it will be present in the HTML source code of the page, so you will be able to access the value using javascript (e.g. using GetElementByID function).


Best regards,
Michal Legen

User avatar
Member
Member
jinijose-gmail - 1/14/2011 7:01:11 AM
   
RE:detect language using javascript
sorry am new to kentico.

did I want to create a user control in .net and upload it to server ?

User avatar
Member
Member
kentico_michal - 1/14/2011 8:06:58 AM
   
RE:detect language using javascript
Hi,

You will need to develop either custom web part if you are using portal engine or user control if you are using aspx templates.
Please find more information about developing web parts in following article Developing web parts.

Best regards,
Michal Legen

User avatar
Member
Member
jinijose-gmail - 1/14/2011 9:20:58 AM
   
RE:detect language using javascript
Lastly I developed my own language selecting dropdown list.
I created a webpartzone and added a static text and put the below code in its default text.
In my case the languages is predefined and it will not change. So it will work perfectly. If you need to add another language you need to add it to this dropdown manually.

here is the code.

<select id="langSelection" name="langSelection" onchange="window.open(window.location.pathname + '?lang=' + this.options[this.selectedIndex].value,'_top')">
<option value="de-DE">Germany</option>
<option value="en-GB">United Kingdom</option>
<option value="en-US">USA</option>
</select>
<SCRIPT LANGUAGE="JavaScript">
var langSelection=document.getElementById('langSelection');
var lng=document.getElementById('lng');
var lngValue=lng.value;
for(i=0;i<langSelection.length;i++)
{
//alert(langSelection.options.value + ' ' + lngValue);
if(langSelection.options.value==lngValue)
langSelection.selectedIndex=i;
}
</script>

User avatar
Member
Member
kentico_michal - 1/18/2011 6:11:01 AM
   
RE:detect language using javascript
Hi,

I am really glad that you found the solution and thank you for letting us know about it.


Best regards,
Michal Legen