5

Have anyone ever implemented multilingual visual web part in SharePoint 2013? I see there are many links out there on this topic but they are not cohesive and complete.

I don't know how can I address my *.resx files? I add Resource Files in my project but there is no C# code behind them. As I remember resx files must have code behind in a particular namespace. What other configuration do I need to achieve this ? How the web part should know when the language changes ?

Please send no links, just please help me if and if you've done that before and it works.

thanks in advance

1 Answer 1

6

Here is a way to do it in sharepoint 2013 in visual studio 2012

1)Create a empty sharepoint 13 solution Farm solution .

2) Add a sharepoin 13 project into it .

3)Add a mapped foder "Resources" to the project .

4)Now you gonna add three resources one for english "testMutliLing.en-US.resx" and one for german "testMutliLing.de-DE.resx" and one default "testMutliLing.resx into the mapped folder.

5)In the designer of resource file add the key and value for both english and german resource file .

6)Now open the ascx file and add "label"

7)In the page load event add the following code

int id=1033;
//to get the default broweser language either "en-US" or "de-DE" etc etc


string a = HttpContext.Current.Request.UserLanguages[0].ToString();
if (a.Contains("en-US")){
id = 1033;
}

else{
id = 1031;
}//german =1031 //english =1033
Label.Text = SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)id);
}

The en-Us is equal to 1033 you get the different language codes for different languages if you browse for it in internet.

or you can even use

Label.Text = SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)CultureInfo.CurrentUICulture.LCID);

Deploy the solution add the webpart to the page .

It shows the english version picking the value for "String1" from english resource file.

to check for german .In IE goto internet options-->Languages-->add german de-DE and make it as default language by moving it to the top .say ok and refresh the page

Now the text for Lable is picked by "String1" from the german resource file.

Also if you want to have multilingual markups you can use as below

<asp:Label ID="lbltest" runat="server" Text="<%$Resources:testMutliLing, String1; %>"></asp:Label> 

you can even use "(uint)CultureInfo.CurrentUICulture.LCID" to get the default browser language

2
  • Thanks,I'm trying your solution. Does the way I name my resource files matters? My Namespace (assembly name) for my web part is "Mahan.WebSite.Controls.EmailSubscription" .. so what would be the name of my resource files ?
    – Pouyan
    Commented Mar 1, 2014 at 5:29
  • ُSucceed .. The problem is resource files in Reource Mapped Folder will not copy to their equivalent folder in 15\Resources in Deployment process. I copied the files manually and it worked. I don't know why they are not being copied when I Deploy the Solution...
    – Pouyan
    Commented Mar 1, 2014 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.