SharePoint JavaScript Resources and Localization

Great article from Wictor Wilén regarding that topic: Announcing new Visual Studio 2012 tool for JavaScript Localization in SharePoint 2013

Short sample code:

function requestUserPolicyDialog() {
    SP.SOD.executeFunc("sp.core.js", null, onSpCoreReady);
}

function onSpCoreReady() {
    SP.SOD.executeFunc("sp.js", null, onSpReady);
}

function onSpReady() {
    SP.SOD.registerSod("MyStrings", "/_layouts/15/ScriptResx.ashx?name=MyStrings&culture=" + STSHtmlEncode(Strings.STS.L_CurrentUICulture_Name));
    SP.SOD.executeFunc("MyStrings", "Res", onResourcesReady);
}

function onResourcesReady() {
    alert(Res.someString);
}

Leave a Reply

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

12 − six =