Get Current UI Language in Sharepoint and Apply CSS at runtime.

From last some day having problem of applying CSS according to the language selected from Language Setting. tried many things then decided to use javascript to apply css at runtime

<script type=”text/javascript”>

/*to run function on page load*/

_spBodyOnLoadFunctionNames.push(‘applyCSS()’);
/*function to apply css according to the selected language*/

function applyCSS(){

/* Get current language in var lcid */
var lcid =_spPageContextInfo.currentLanguage;

/* 1033 for english language (to get more lcid of language refer this )*/
if(lcid == 1033)
{

/*to apply css*/
var headID = document.getElementsByTagName(“head”)[0];
var cssNode = document.createElement(‘link’);
cssNode.type = ‘text/css’;
cssNode.rel = ‘stylesheet’;
cssNode.href = ‘path to css’;
cssNode.media = ‘screen’;
headID.appendChild(cssNode);
}

</script>

and bingo…. done….

Advertisements

2 comments on “Get Current UI Language in Sharepoint and Apply CSS at runtime.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s