JavaScript Localization in SharePoint
Anatoly Mironov
Yesterday Waldek Mastykarz published a cool post: Globalizing JavaScript in SharePoint 2013. This is a very cool technique to localize your client code in javascript and reuse your resx files in Server Side and Client Side. This is actually not new for SharePoint 2013 despite it has become more needed with the huge client focus in the new SharePoint. I have used this in SharePoint 2010 for a long time. In my blog post: ScriptResx.ashx in SharePoint I told about that technique. What I didn’t know that you can define your javascript namespace directly in the resx file. Waldek wrote in his comment that SP.Publishing.Resources.en-US.resx automatically are SP.Publishing.Resources in javascript. That was not the case for my own localization files. A simple look at SP.Publishing.Resources.en-US.resx helped: 
<!--
Whether this .resx could be read by scriptResx.ashx handler. Only a file
marked with scriptResx:true could be returned to client.
-->
<resheader name="scriptResx">
<value>
true
</value>
</resheader>
<!-- the full name of the JavaScript class. -->
<resheader name="classFullName">
<value>
SP.Publishing.Resources
</value>
</resheader>This results in:
_EnsureJSNamespace('SP.Publishing');So what we have to do for our custom resx file is to add classFullName resheader:
<resheader name="classFullName">
<value>
Takana.Res
</value>
</resheader>comments from wordpress
thomasdah — 2013-02-01
Here some additional info about localization with angular: http://stackoverflow.com/a/15056198/1433691
ScriptResx.ashx in SharePoint « Share… What? — 2013-02-05
[…] JavaScript Localization in SharePoint […]
Anatoly Mironov — 2013-03-02
Thank you Thomas. The combination SharePoint + Angular is awesome and scriptresx localization can help localizing the new sharepoint apps.
Johan Frisell — 2013-02-04
Great post - as always :)
Anatoly Mironov — 2013-02-04
Tack Johan!
Daniel — 2013-02-01
The problem is that i can’t use the …to reference because i’m trying to load directly from javascript thanks!
Daniel — 2013-02-01
Not work! I’ve used now
RegisterSod("test.sp.publishing.resources.resx", "/_layouts/ScriptResx.ashx?name=test.sp.publishing.resources&culture=en-US");If paste url in Chrome i can see correctly: “_EnsureJSNamespace(‘TEST.SP.Publishing’); TEST.SP.Publishing.Resources={..” But just execute RegisterSod(…..); Try to use TEST.SP.Publishing.Resources and console return “ReferenceError: TEST is not defined” Thnks!
Anatoly Mironov — 2013-02-01
Allright. So there is no problem with the script reference. It is just SP.SOD handling. The easiest way is not to use SP.SOD just reference your script like <script src="/_layouts/ScriptResx.ashx?name=test.sp.publishing.resources&culture=en-US"></script> When you want to take an advantage of SP.SOD you must check the documentation for SP.SOD: RegisterSod doesn’t load your script.
Daniel — 2013-02-01
Hi! Great post! I’m try to use my own localization file, i register it using
SP.SOD.registerSod("test.sp.publishing.resources.resx", "/_layouts/ScriptResx.ashx?name=test.sp.publishing.resources&culture=en");I´m using the namespace TEST.SP.Publishing, but i can’t access it from javascript. Something wrong? Thanks!
Anatoly Mironov — 2013-02-01
Hi Daniel! Try to get it to work without SP.SOD first. Just paste your url in Chrome and see what you get. I think, culture has to be defined like “en-US”, not just (“en”).
Anatoly Mironov — 2015-02-04
Hi, Kannan. Every time you update the resource file in Visual Studio, it resets the classFullName. Unfortunately, you have to update it every time.
Kannan — 2015-02-01
Hi Anatoly, I defined a resource file with scriptResx and classFullName elements but when I run the url from browser its blank. Any Ideas how to troubleshoot this…