SharePoint MUI Resource files
In SharePoint 2010 you have the ability to configure alternate languages for a website, this feature enables that navigation and labels are presented in the user selected language without creating variations, when on a farm multiple language pack’s are deployed you can configure Alternate Languages on every site.
Configure Multilangual User Interface
- goto site settings –> Language Settings
-
select the languages of choise.
-
press OK to save changes.
Change Language on Site
The language of the current site can be changed by slecting the ‘Select Display Language’ in the user menu
Using Labels in your solution
When you want to use different languages in your custom solutions it is possible to make use of resource files withing SharePoint.
The SharePoint object model provides Helper methods to get localized strings, the following article on MSDN explains how to use this: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.getlocalizedstring.aspx
Get current language of user
With SPWeb.Language you get the ‘default’ language of the site in the case of alternate languages it is not sufficient to use this because a user could have set the language to a non ‘default’ language.
The current language of a user can be found at: CultureInfo.CurrentUICulture.LCID
The following Helper method can be used to retrieve localized strings with respect to the user selected language.
public static string GetResourceString(string resourceName, string name) { int languageId = 1033; if (SPContext.Current != null && SPContext.Current.Web != null) { //Set Language to default language of web object! languageId = (int)SPContext.Current.Web.Language;
<span style="color: green;">//if alternate language is selected by user! </span><span style="color: blue;">if </span>(<span style="color: #2b91af;">SPContext</span>.Current.Web.IsMultilingual &&
<span style="color: #2b91af;">SPContext</span>.Current.Web.SupportedUICultures.Where(w => w.LCID == <span style="color: #2b91af;">CultureInfo</span>.CurrentUICulture.LCID).
Any())
{
languageId = <span style="color: #2b91af;">CultureInfo</span>.CurrentUICulture.LCID;
}
}
<span style="color: blue;">return </span><span style="color: #2b91af;">SPUtility</span>.GetLocalizedString(resourceName, name, (<span style="color: blue;">uint</span>)languageId);
}