Sharepoint 2010 - Multilanguage Site - Show column in current language

In multilanguage site feature, Sharepoint 2010 does not translate content of web part and metadata.
We have to find a way to show to user content or metadata in current language.

I used a list with columns with content in language and a lot of jquery to show and hide columns for current language.



I have a list with "DescriptionIT" and "DescriptionEN" columns.
Then, I set a view with both columns visible.
In this view, I added a content query web part whit code below.

In this code, I search for current language, i.e. "Italian", then search for column with "DescriptionIT", and hide all columns but "DescriptionIT" (with name starting with "Decsription").

Result is that if I change language (with Select Display Language), I see only column in respective language.



Simple and cross platform.

Here the code:


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

function DisplayLanguage(column)
{

 var langCode = _spPageContextInfo.currentLanguage;

 var columnEnglish = column+"EN";
 var columnItalian = column+"IT";
 var columnChinese = column+"CH";
 var columnSlovacchia = column+"SL";
 var columnSpanish = column+"ES";

 //
 var parentThName;
 var parentTh;
 //
 switch(langCode)
 {
    case 1033:
parentThName = columnEnglish;
        break;
    case 1040:
parentThName = columnItalian;
        break;
    case 1028:
parentThName = columnChinese;
        break;
    case 1051:
parentThName = columnSlovak;
        break;
    case 1034:
parentThName = columnSpanish;
        break;
    default:
  parentThName = columnEnglish;
        break;
 }

 //get column id to show
 parentTh = $("div[name='"+parentThName+"']").parent();
 parentThIndex = parentTh[0].cellIndex;
 //get all ths with Description
 allTh = $("div[name^='"+column+"']").parent();
 allTh.each(function(item){
    //hide all column but language column
    if($(this).index() != parentThIndex)
    {
  //hide
$(this).hide();
//get its id
var indth = $(this)[0].cellIndex;
//hide all cell of this column
$("td.ms-vb2").each(function(item){
   if($(this).index() == indth)
   {
$(this).hide();
   }
        });
    }
 });
}

DisplayLanguage("Description");

</script>


Comments

  1. I trying to do the same thing. Where did you put that script?

    ReplyDelete
  2. You can try in a content editor web part at The bottom of the page or in master.page file.

    ReplyDelete

Post a Comment

Popular posts from this blog

Sharepoint 2010 - Enable/Disable Ribbon Button with EcmaScript

Sharepoint 2010 - Customizing Quick Launch with pages

SharePoint - Add button Apply to List Item Edit Form for Saving Item without closing form