Nov 07

Well, what about this one? Beta 2 offers support for automatic loading of localized scripts (I hope i got the word right). So, why is this good? Here”s a quick example: suppose you need to show messages to the user in the client side and you also need to support users that speak two different languages. How will you do that? maybe by inserting a global variable from an ASP.NET page which tells you the current locale so that you can show the correct error message? Well, guess what (oki, you”ve already guessed it by know, right?): you can do this easily. The idea is simple; you define your main library file and then several resource javascript files which contain specific locale values for global variables which you”re using from your library. So, let”s start by creating the “main” library (a simple js file will do it):

alert( info );
if( Sys && Sys.Application ){

Nothing new here… the only thing to remember is that info will be inserted by one of the resource files. When you build resource files you must use a predefined name convention: you should call your files library_filename.culture.js. To illustrate what  I mean, i”ll create 2 resource files: one in pt and another one in en:

var info = “Ola”
if( Sys && Sys.Application ){

// localizado.en-UK.js
var info = “hello”
if( Sys && Sys.Application ){

The platform can load the correct file for you: you just need to set the EnableScriptLocalization property to true and add the necessary entries to the ResourceUICultures of the ScriptReference element. Btw, don”t forget to configure the ASP.NET page to use the correct culture (in this case, I”m using the Auto option so that the current UI culture depends on the language defined on the browser):

<%@ Page Language=”C#” Culture=”Auto” UICulture=”en-UK” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>
<html xmlns=”” >
  <head runat=”server”>
     <title>Untitled Page</title>
<form id=”form1″ runat=”server”>
<asp:Scriptmanager runat=”server” id=”manager” EnableScriptLocalization=”true”>
      <asp:ScriptReference Path=”localizado.js”
          ScriptMode=”release” ResourceUICultures=”en-US, pt-PT” />
     <asp:ScriptReference Path=”localizado.js” 
           ScriptMode=”release” />

And that”s all for today.

1 comment so far

  1. airline tickets
    3:41 pm - 5-14-2007

    Hi. Great site.