Request a Quote

Accessing resource file value in JavaScript in Multilingual site in SharePoint 2013

Accessing resource file value in JavaScript in Multilingual site in SharePoint 2013

Writing server side code to get resource file value in JavaScript is the easy way and most people using server side code to get resource file value. But when there is a requirement to write advanced JavaScript based development and to get resource file value in the JavaScript file (.js) at that time we need to write the JavaScript code. Below is the JavaScript code to get resource file value.

Resource File Image:

b3

 Javascript Code:

$(document).ready(function () {

    var eventName = "";

    //load the authoring resource file depending on the current language
    function loadResourceJs() {
        currentUiCluture = STSHtmlEncode(Strings.STS.L_CurrentUICulture_Name);
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getResourceVal);
    }

    //get resource strings from ‘EventNotification’ resource file depending on the current language
    function getResourceVal() {
        var resourceUrl = '/_layouts/15/ScriptResx.ashx?culture=' + currentUiCluture + '&name=EventNotification;

        $.getScript(resourceUrl, function () {
            eventName = Res['eventName'];
        });
    }

    SP.SOD.executeOrDelayUntilScriptLoaded(loadResourceJs, 'core.js');
});

 

The resource file should be deployed in the 15 hive and resource file should be language specific resource file. Here Culture is the locale language for the resource file. If the language is de-de then it will get the value from German resource file and if the language is en-us then it will get the value from English resource file.

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2015 Trimantra Software Solution LLP- Software Outsourcing Company India. All rights reserved.