Jane's Technical Stuff

Tuesday, June 26, 2007

Localisation


The current project I'm working on is going to be delivered in Dutch. I figured I had 2 choices, the hard coded method or a resource based method. The hard coded method would be ok, but as the whole of the site is being presented in Dutch my fear was that it would make testing, and maintenance incredible hard (for the record I don't speak Dutch!). The resource based method might take slightly longer to implement, but not enough to prevent me from doing it.

So, I'm using the .NET ResourceManager class to manage my resources files and using resgen to take a text file of name value pairs and generate the .resources file.

My naming strategy for the text items are XXX_YYY_Key where:
XXX is the main area of the project - i.e. admin, front end, etc
YYY is the module of the area - i.e. article, menu, etc
Key is the "thing" we're providing text for - i.e. title, contact name, email address, etc
so, ADMIN_ARTICLE_Title = Title etc

I have 2 files, one in English, one in Dutch and I use an appSetting in my web.config file to specify what my DefaultCulture should be. The site will only run in either Dutch or English so there is no need to make anything more complicated that this, and it allows development and maintenance to be affected in English, whilst the live site is presented in Dutch.

This is all working well, but then I got to thinking about the javascript and drew a blank through my google searching. Some of my javascript files perform validation, and alert the user with appropriate messages if the content isn't valid. I asked some of my local brains and still came up with a blank, a few names were banded about, but I didn't get to HackDay and so didn't get to pick their brains.

At the moment, I've added a line to my resources file to contain the javascript file to include in the file. This allows there to be muliple validation files, one per language if I want - at the moment there is just one file and it's in Dutch. But really this isn't a great solution. I've started doing some investigation and playing, but haven't really had the time to progress it any further.

The current 4 options to do this that I can think of are:
  1. Basic - 2 javascript files, one per language - duplicate functionality
  2. Literals - 3 javascript files - one per language, plus one with functionality
  3. A self detecting piece of javascript that works out the locale from some setting and thus includes the appropriate literals file (or other data store method) dynamically
  4. A method using a better form of data store than variables

Anyone done any localisation/localization in javascript and got any more options or solutions for me?

Labels: , , , ,

// posted by Jane @ 7:47 PM   save to del.icio.us

Comments:
Guy Smith-Ferrier is your man. He's a regular DDD speaker (including Saturday), and an internationalisation expert, such that he's written a book about it. He's friendly and approachable too.
 
Thanks Simon

Unfortunately I was too slow to sign up for DDD and so won't be there on Saturday :-(

Will take a look at his site and his book. Thanks again!
 

Thursday, April 26, 2007

ASP.NET: sql cache dependecy


I stumbled across some of the Microsoft Virtual Labs the other day and thought I'd give the ASP.NET ones a try. My theory was that whilst they were pretty basic, there may well be areas that I just didn't know about. I've just been doing the ASP.NET 2.0 Data Access Virtual Lab and discovered the SQL Cache dependency. In recent projects we have always separated our data layer out completely, and made use of the Microsoft.ApplicationBlock.Data code to control our data access and so haven't needed to know about the EnableCaching property and its impact. So, the moral of this story is that they're worth persisting with even though they can be quite slow some times.

Labels:

// posted by Jane @ 3:25 PM   save to del.icio.us

Comments:

Wednesday, January 17, 2007

ASP.NET: validators and client code


I found myself with a bit of a challenge yesterday. I have a form which has client validation but also has a message displayed back from the server after a save.

When a save happens a "Update successful" message is displayed on the screen as an <asp:label>.

When the client side validation happens, then one of many error messages are displayed on the screen.

This means that both the "Update successful" and the error messages are displayed on the screen at the same time. This obviously isn't ideal and doesn't give the user a clear message.

For a while I was going to do this using a <asp:customvalidator> calling some javascript to clear out the label. And then I read "The custom validation subroutine is not called when the control being validated does not contain any data. The only control that you can use to check for an empty form field is the RequiredFieldValdiator control" which scuppered those plans.

I then did a bit of googling and discovered that I could use the Attributes property to get at the client side events of an element. So, a bit of code that does
TextBox1.Attributes["onblur"] = "for(i=0; i<document.all.length; i++){if (document.all[i].id.indexOf('Label1') > -1) { var element = document.all[i];element.innerHTML='Changes have been made';};}";
works like a charm and when focus leaves TextBox1, the text in the element Label1 changes to be "Hello".

I then manipulated it a bit more and discovered that if in the html the Label1 element is set to visible="false", then the javascript fails due to the non-existance of that element.

So, the final result is:

The basic form:


When a required field is missing (note both the validator text and the change of text in the label caused by changing the focus):


When the two textboxes don't have identical content:


With asp code of:

<asp:Label ID="Label1" runat="server" Text="Label">Please make some changes</asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server">TextBox1</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1" Text="RequiredFieldValidator"></asp:RequiredFieldValidator>
<br />
<asp:TextBox ID="TextBox2" runat="server">TextBox2</asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator" ControlToCompare="TextBox2" ControlToValidate="TextBox1">CompareValidator</asp:CompareValidator><br/>
<asp:Button ID="Button1" runat="server" Text="Button" />


and a code behind of

protected void Page_Load(object sender, EventArgs e)
 {
  if (Label1.Visible)
  {
   TextBox1.Attributes["onblur"] = "for(i=0; i -1) { var element = document.all[i];element.innerHTML='Changes have been made';};}";
  }
 }

Labels: ,

// posted by Jane @ 1:40 PM   save to del.icio.us

Comments:

Sunday, December 03, 2006

MS2543 - Core Web Application Technologies Course - Days 2 & 3 / MS2544 - Advanced Web Application Technologies - Days 1 & 2


It was quite a packed week, with lots of hints and tips gained as well as an insight into the way we can progress our web products to make the most of the .Net framework. We even had some spare time to take a look at ASP.NET Ajax which looks really handy.

Some of the most pertinent things to have come out of the course are things like session state management, specially with regards to the server farm environment - something we've had a problem with for a while.

The best thing for have come out of the course though was probably the opportunity to experiement, to try some things out and to work out how to integrate our learnings into our projects.

Labels: ,

// posted by Jane @ 3:23 PM   save to del.icio.us

Comments:

Tuesday, November 28, 2006

MS2543 - Core Web Application Technologies Course - Day 1


My team have been given a new project to work on, which is improvements to the current functionality offered by an ASP.NET 2/C# product. To this end, we've highlighted a couple of courses as a way to get up to speed to enable us to maintain and enhance this product going forward.

Xpertise have come into the office, and we've taken over the boardroom to have a week long course covering both the Core Web Application Technologies, and the Advanced Web Application Technologies workshops.

Yesterday was the first day of the course, and covered off several of the basics, covering the creation of a web application using a file system web server, doing some basic programming, handling errors nicely and also starting to look into using server controls and the use of postback.

So far I'm enjoying it, and its starting to make the source code that I looked at last week for the new product far easier to understand. My last forray into web development using Microsoft tools was back in 2003 when I last did some ASP work. I'm hoping to be able to lead by example and do some development as well as recommendations and design work.

Labels: ,

// posted by Jane @ 10:56 AM   save to del.icio.us

Comments:

Brighton Bloggers   This page is powered by Blogger. Isn't yours?   rss Sussex Digital - focusing on the Sussex digital community