Monday, November 03, 2008

Localizing a Custom UI in Dynamics CRM 3

While working on a project using Microsoft's latest Dynamics CRM installment (4.0) we needed a dashboard like page running on an IIS site that was localized according to the CRM user's locale. If you're reading this you probably already know CRM user's have a locale attribute. CRM uses this to localize the UI and not the browser's locale setting. Create an ASP.net page based on the browser setting was quite simple (even for an ASP.net noob like me!)

The following is what I did to use CRM's locale setting.

In the web.config include the following:


<globalization culture="auto" uiculture="auto">


This should be placed inside the system.web node. It enables the app to be localized. Once this is in place insert this code into the page's backing code file (ie: Default.aspx.cs or whatever it's named)



protected override void InitializeCulture()
{
this.orgname = Request.QueryString["orgname"];
this.orglcid = Request.QueryString["orglcid"];
this.userlcid = Request.QueryString["userlcid"];
if (userlcid == null) { lcid = orglcid; }
else { lcid = userlcid; }
if (lcid != null) {
// Only set the Culture if CRM passed us the locale.
// If not it will be automatically set to the browser setting..
CultureInfo culture = new CultureInfo(int.Parse(lcid));
Culture = culture.Name;
UICulture = culture.Name;
}
}



This code is relying on CRM to pass the orglcid and userlcid (organization's default locale id and
the user's locale id). To enable this add "PassParams=true" to the link's entry in the sitemap.

That's pretty much it.. Now when I reference a properties from my asp page like this:


<asp:Label ID="Label3" runat="server" Title="<%$ Resources:Resource, com_foo_dashboard_time_title %>">


It will be localized according to the user's CRM setting.

Happy coding.
Gary

0 Comments:

Post a Comment

<< Home