DNN Blog

Jul 25

Posted by: Néstor Sánchez
Friday, July 25, 2008  RssIcon

Today Core Team member Vincenç Masanas gave a presentation about Localization in DotNetNuke. And it reminded me about the use of a Client API feature that has received little publicity.

Dotnetnuke is very lucky to have Jon Henning as part of the Core Team and the Client API is mainly a result of his work on the area. While my Gallery team mate Matthias Schlomann was doing work to make Gallery an XHTML compliant module, he also did extensive work to complete localization. One particular scenario where the usual method of localization requires an extra bit of work is related to string retrieval through Javascript.

Gallery has several places where JS is used to provided enhanced functionality for the module. For example inner navigation menus and popups that are particular to the Gallery can be found. In fact Forum and Gallery were the first modules where I found separate JS files were used. You will notice that most other Core Projects do not use JS as much as these two.

Of course, localizing texts in the browser using client side code has the potential of generating errors. Fortunately a ClientAPI method can be used to retrieve a localized string value that can be used with JS. The method is ClientAPI.GetSafeJSString() from the Dotnetnuke.UI.Utilities.ClientAPI namespace will escape a sequence of characters for safe javascript use. The method accepts a string and used in combination with the Localization GetString() method, you may grab a localized value from anywhere and inject it into your javascript.

Here's an example: <code> var sNoneSpecified = '<%=ClientAPI.GetSafeJSString(Localization.GetString("myString", LocalResourceFile)) %>'</code>

2 comment(s) so far...


Re: Using the ClientAPI to retrieve safe JS strings for Localization in Gallery

Thanks for sharing the tip!

By sunwangji on   Sunday, July 27, 2008

Re: Using the ClientAPI to retrieve safe JS strings for Localization in Gallery

If you wish to carry the localization to the client a bit further, I would recommend looking at how my AJAX templates handle it in this video.
http://blip.tv/file/get/Codeendeavors-ProgrammingWithTheCodeEndeavorsAJAXModuleTemplate676.wmv

The source code for the templates can be found here: http://www.codeplex.com/codeendeavortemplate/Release/ProjectReleases.aspx?ReleaseId=9057

By jhenning@solpart.com on   Monday, July 28, 2008
Attend A Webinar
Free Demo Site
Download DotNetNuke Professional Edition Trial
Have Someone Contact Me

Like Us on Facebook Join our Network on LinkedIn Follow DNN Corporate on Twitter Follow DNN on Twitter

Advertisers

Sponsors

DotNetNuke Corporation

DotNetNuke Corp. is the steward of the DotNetNuke open source project, the most widely adopted Web Content Management Platform for building web sites and web applications on Microsoft .NET. Organizations use DotNetNuke to quickly develop and deploy interactive and dynamic web sites, intranets, extranets and web applications. The DotNetNuke platform is available in a free Community and subscription-based Professional and Enterprise Editions with an Elite Support option. DotNetNuke Corp. also operates the DotNetNuke Store where users purchase third party apps for the platform.