CHUVASH.eu

CHunky Universe of Vigouros Astonishing SHarepoint :)

JavaScript Localization in SharePoint

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:

scriptresx

  <!-- 
    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>
About these ads

10 Responses to JavaScript Localization in SharePoint

  1. Pingback: ScriptResx.ashx in SharePoint « Share… What?

  2. Johan Frisell 2013-02-07 at 11:43

    Great post – as always :)

  3. Daniel 2013-02-18 at 13:48

    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-18 at 13:52

      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”).

  4. Daniel 2013-02-18 at 14:05

    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-18 at 14:10

      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-18 at 15:54

        The problem is that i can’t use the …to reference because i’m trying to load directly from javascript

        thanks!

  5. thomasdah 2013-02-25 at 14:54

    Here some additional info about localization with angular:
    http://stackoverflow.com/a/15056198/1433691

    • Anatoly Mironov 2013-03-19 at 10:21

      Thank you Thomas. The combination SharePoint + Angular is awesome and scriptresx localization can help localizing the new sharepoint apps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

SharePoint Dragons

Nikander & Margriet on SharePoint

The Zuul Cat Idea Brewery

Where ideas on software development and entrepreneurship brew.

Paul J. Swider

Smooth Sailing with SharePoint

Mai Omar Desouki - Avid SharePointer

Infusionite Software Consultant

Alexander Ahrens

MCPD | SharePoint | Web Development | JavaScript | .NET

Cameron Dwyer | SharePoint, Outlook, OnePlaceMail

OnePlaceMail, SharePoint, Outlook & Life's Other Little Wonders

.:paul.tavares:.

Me and My doings!

Share SharePoint Points

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Virtualize SharePoint and SharePoint Virtualization

SharePoint 2010, Design, Customization and Configuration

SPJoel

SharePoint for everyone

SharePointRyan.com

Ryan Dennis (MCTS, MCPD, MCITP) is a SharePoint Solutions Architect focusing on SharePoint Architecture, PowerShell Automation and General Enhancements

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode, ya mama

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

blksthl

Mostly what I know about SharePoint - CommunicoCuspis

SharePointDiver

SharePoint på ren svenska

Me & My SharePoint Design

© Christian Stahl - All about SharePoint branding & customizations

SC Vinod's Blog

Just another WordPress.com weblog

Follow

Get every new post delivered to your Inbox.

Join 79 other followers

%d bloggers like this: