How to make MS CRM 2011 ADX Studio Customer Portal MultiLingual

I had some issues making the ADX Studio Customer Portal multilingual.
First I tried having a duplicate website with duplicatie site markers and all… this was way too much.

I solved it just a little easier… use as much translations from CRM as possible… since there are a whole load of translations available when you install a language pack.
In this article I use Dutch and English.

First let me show you the markup for a page with a grid view displaying CRM data.

asp:GridView
ID=”GridView1″ runat=”server” CssClass=”cases” AutoGenerateColumns=”False”
>


<Columns>

    <asp:TemplateField
HeaderText=”Study”>

        <HeaderTemplate >

            <asp:Literal
ID=”ltrHeader1″ runat=”server” Text=’<%# GetHeaderText(“cbr_study”) %>‘></asp:Literal>

        </HeaderTemplate>

        <ItemTemplate>

        <asp:HyperLink
ID=”hlUrl” runat=”server” NavigateUrl=’<%# EducationUrl( (Guid)Eval(“cbr_educationid”) ) %>

Text=’<%# Eval(“cbr_study”)%>
/>

        </ItemTemplate>

    </asp:TemplateField>

    <asp:TemplateField
HeaderText=”Institution”>

        <HeaderTemplate >

            <asp:Literal
ID=”ltrHeader2″ runat=”server” Text=’<%# GetHeaderText(“cbr_institutionid”) %>‘></asp:Literal>

        </HeaderTemplate>

        <ItemTemplate>

            <%#
ContentUtility.FormatCrmEntityReference(Eval(“cbr_institutionid”) as
CrmEntityReference) %>

            <%# Eval(“cbr_institute_not_listed”)%>

        </ItemTemplate>

    </asp:TemplateField>

    <asp:TemplateField
HeaderText=”Start Date”>

        <HeaderTemplate >

            <asp:Literal
ID=”ltrHeader3″ runat=”server” Text=’<%# GetHeaderText(“cbr_startdate”) %>‘></asp:Literal>

        </HeaderTemplate>

        <ItemTemplate>

            <%# GetLocalDate(Eval(“cbr_startdate”) as
DateTime?) %>

        </ItemTemplate>

    </asp:TemplateField>

    <asp:TemplateField
HeaderText=”End Date”>

        <HeaderTemplate >

            <asp:Literal
ID=”ltrHeader4″ runat=”server” Text=’<%# GetHeaderText(“cbr_graduationdate”) %>‘></asp:Literal>

        </HeaderTemplate>

        <ItemTemplate>

            <%# GetLocalDate(Eval(“cbr_graduationdate”) as
DateTime?)%>

        </ItemTemplate>

    </asp:TemplateField>

    </Columns>

</asp:GridView>

 

In the code behind of this page, you´ll need the method GetHeaderText… taking the CRM field name as only argument..

In the Session-object I stored MyLanguageCode… holding the 1033 or 1043… whatever the user picked as display language.

 

protected
string GetHeaderText(string crmField)

{

return
ContentUtility.GetLocalizedLabel(XrmContext, crmField, “cbr_education”, (int)Session[“MyLanguageCode”]);

}

 

I add in the ContentUtility class a two methods … GetLocalizedLabel and GetLocalizedPickListValues

 

public
static
string GetLocalizedLabel(XrmServiceContext context, string crmField, string crmEntity, int LanguageCode)

{


RetrieveAttributeRequest CrmAttributeRequest = new
RetrieveAttributeRequest();

CrmAttributeRequest.EntityLogicalName = crmEntity;

CrmAttributeRequest.LogicalName = crmField;

 


RetrieveAttributeResponse response = (RetrieveAttributeResponse)context.Execute(CrmAttributeRequest);

 


if (response.AttributeMetadata.DisplayName.LocalizedLabels.Where(l => l.LanguageCode == LanguageCode).Any() == true)

{


return response.AttributeMetadata.DisplayName.LocalizedLabels.Where(l => l.LanguageCode == LanguageCode).SingleOrDefault().Label;

}

 


// Otherwise return the default label


return response.AttributeMetadata.DisplayName.LocalizedLabels.Single().Label;

}

 

public
static
ListItemCollection GetLocalizedPickListValue(XrmServiceContext context, string crmField, string crmEntity, int LanguageCode)

{


RetrieveAttributeRequest CrmAttributeRequest = new
RetrieveAttributeRequest();

CrmAttributeRequest.EntityLogicalName = crmEntity;

CrmAttributeRequest.LogicalName = crmField;

 


RetrieveAttributeResponse response = (RetrieveAttributeResponse)context.Execute(CrmAttributeRequest);


PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;

 


ListItemCollection ddItems = new
ListItemCollection();


string _localizedlabel = string.Empty;

 


foreach (OptionMetadata option in picklist.OptionSet.Options)

{


if (option.Label.LocalizedLabels.Where(l => l.LanguageCode == LanguageCode).Any() == true)

{

_localizedlabel = option.Label.LocalizedLabels.Where(l => l.LanguageCode == LanguageCode).SingleOrDefault().Label;

}


else

{

_localizedlabel = option.Label.LocalizedLabels.Single().Label;

}

 

ddItems.Add(new
ListItem(_localizedlabel, option.Value.ToString()));

}


return ddItems;

}


 

Advertisement

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 )

Facebook photo

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

Connecting to %s