Content Localization in SharePoint 2013 using resource files

SharePoint supports content localization to enable the site members to have a SharePoint site in their very own languages. This is very innovative feature of SharePoint with which one can create multilingual sites very easily.
When it comes to creating a multilingual site, particularly, a developer concentrates on the parts on which localization is to be applied. As we know for any SharePoint site, we have a page, where we have, page content, few webparts, header and footer.
With advent of Machine Translation Service in SharePoint 2013, one can easily have a translation of page content by using Microsoft Translator Service. As far as other parts of the page are concerned, web part, particularly, can have some difficulties translating each and every content.
For the same, we can use a resource file, which will enable the webpart interface to adopt to specific language. In this particular post, I will be describing a step by step method to get some content localized by using resource file.

Instructions to create the webpart

Create an empty Visual Studio Project.

Content_1

Provide a website to debug the solution and select “Deploy as farm solution”.

Content_2

Let us add a visual webpart in the solution, named SampleWebPart using New Item option in Add menu.

Content_3

I have added two labels with the id as shown below.

Content_4

It is time to add our resource files. For the same, we’ll map a resource folder

I will right click on the solution and select Add, where I will find SharePoint Mapped Folder.

Content_5

Content_6

After selecting resources in the proceeding screen, I will be able to see a resources folder in my solution.

In the Resources folder, I will create the resource file, by clicking Add Item.

Note the file name for the resource file: Resource.en-US.resx

Content_7

Add some content to the resource file.

Content_8

In the same way, create another resource file for the other language required.

Content_9

Now we’ll do some programming to get our localization working.

Add following two lines in Page_Load event in SampleWebPart.ascx.cs.
Content_10
Create a function named LoadResource along with an enum as shown below.

Content_11

We are ready to go!

Just build and deploy the solution!

The preview on English Site

Content_12

The Preview on Hindi Site:

Content_13

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s