LA.NET [EN]

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):

//localizado.js
alert( info );
if( Sys && Sys.Application ){
      Sys.Application.notifyScriptLoaded();
}

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:

// localizado.pt-PT.js
var info = “Ola”
if( Sys && Sys.Application ){
    Sys.Application.notifyScriptLoaded();
}

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

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” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” >
  <head runat=”server”>
     <title>Untitled Page</title>
   </head>
<body>
<form id=”form1″ runat=”server”>
<asp:Scriptmanager runat=”server” id=”manager” EnableScriptLocalization=”true”>
  <Scripts>
      <asp:ScriptReference Path=”localizado.js”
          ScriptMode=”release” ResourceUICultures=”en-US, pt-PT” />
     <asp:ScriptReference Path=”localizado.js” 
           ScriptMode=”release” />
  </Scripts>
</asp:Scriptmanager>
</form>
</body>
</html>

And that”s all for today.

1 comment so far

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

    Hi. Great site.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>