Localizing Display Templates in SharePoint 2013

Display Templates can also use resource files to favor a multilingual user interface for your SharePoint 2013 site. By looking at the default display templates ( e.g. : Item_Picture3Lines.html, Control_List.html etc. ), I have noticed how language files are used.

The first step would be to deploy a resource file to the master page gallery. This should be a JavaScript file which registers a resource dictionary.

{"resourceKey1": "resourceValue1",
"resourceKey2": "resourceValue2",
"resourceKey3": "resourceValue3"});

The resource file should be deployed to the master page gallery of the site in the Language files folder. Here is an example for a display template used in content search web parts : “_catalogs/masterpage/Display Templates/Language Files/en-US/LocalizedFile_Strings.js” . You have to deploy such a file for each culture you plan to support.

From your display template, you would have to reference the above resource file, using

$includeLanguageScript(this.url,"~sitecollection/_catalogs/masterpage/Display Templates/Language Files/{Locale}/LocalizedFile_Strings.js");

In order to reference a key from your file, you can use :

var localizedResource = $resource("resourceKey1");

That;s it! Now you have localized your display template.

1 comment

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: