Monday, April 15, 2013

SharePoint 2013 Localizing Display Template

SharePoint 2013 is new and we didn't find documentation for  many items. One of missing items detailed documentaion about scripts in display templates.

I need to localize my template after I checked existing templates I found localization through JavaScript:
  1. They added local string in resource javascript file. You can create a JavaScript and add to your code as below:
    <script>
      $includeLanguageScript(this.url, "~sitecollection/_catalogs/masterpage/Display Templates/Language Files/{Locale}/YourCustomStrings.js");
    < /script >
  2. Code you will add to JavaScript:
    // Add your custom localized strings and then include these string dictionaries in your display templates using the $includeLanguageScript function

    $registerResourceDictionary("en-us", {
    "sampleCustomStringId": "Sample custom string",
    "rf_RefinementTitle_ManagedPropertyName": "Sample Refinement Title for ManagedPropertyName"
    });
  3. To access resource using the following code:
    var diagRes = $resource("item_Diagnostic_ItemTitleFormat");

No comments: