Merging Localized Resource Files
Complex and global web applications frequently require localized JavaScript and CSS. There are many ways to perform that task. Microsoft Ajax Minifier provides support for merging RESX string resource files directly into your code at build time.Let’s start off with an example. Let’s say you have a RESX file names “strings.resx” in your project that contains two localizable strings. The first one is called “Greeting” and contains a string that will be written to the DOM using a document.write call. The second one is called “Praise” and is used as the text of an alert box:
Cannot resolve image macro, invalid image name or id.
To “compile” this RESX file into your JavaScript source code, you supply the path to the RESX file and a global object name in the command line of ajaxmin via the –RES option:
-RES:global path {code:html The global portion is a valid JavaScript identifier that your code expects to be defined containing all the globalized strings in the resource file. It should not be an identifier that is actually defined within your source; Microsoft Ajax Minifier will take care of integrating the virtual object into your code. The path portion is the path to the RESX file. For instance, if your code expects the strings.resx file to be using a global resource object named “Strings,” you would specify this on the command line of ajaxmin:
document.write("<h1>" + Strings.Greeting + "</h1>"); alert(Strings.Praise);ajaxmin foo.js –RES:Strings strings.resx
document.write("<h1>Hello!</h1>");alert("Excellent!")ajaxmin foo.js –RES:Strings strings-zh.resx
document.write("<h1>\u4f60\u597d\uff01</h1>");alert("\u771f\u68d2\uff01")var Strings={Greeting:"Hello!",Praise:"Excellent!"};
document.write("<h1>" + Strings.Greeting + "</h1>");
alert(Strings.Praise);
body { /*[BodyFontFamily]*/ font-family: Arial; /*[BodyColor]*/ color: black; }
If your RESX file looks like this:
Cannot resolve image macro, invalid image name or id.
Then the resulting CSS when using the –RES option would be:
{code:html}
body{font-family:Segoe UI;color:#009}
{code:html
If the RESX file does not contain a string with the name specified in the comment, the next property value is left as-is and not replaced.