I'm currently doing some work on looking into producing a localised version of a
Madgex job board (not dis-similar to the
work I did this time last year)and am mainly looking at the SQL Server and javascript areas whilst a colleague looks at the .NET side.
Glenn gave me a tip off that when he'd been doing something similar, he'd had problems with Visual Studio 2005 not saving his javascript files as UTF.
So, within VS2005 I created a javascript file and put 2 lines into it. They were simply:
alert ('hello world');
alert('Zarys gramatyki por¢wnawczej jezyk¢w slowianskich');I then linked this into a (very) basic HTML page
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>i18n</title>
<script type="text/javascript" src="js/i18n.js" language="javascript"></script>
</head>
<body>
</body>
</html>so that on pageload 2 alert boxes are displayed, one saying 'Hello World' and the one saying 'Zarys gramatyki por¢wnawczej jezyk¢w slowianskich'.
Unfortunately what is displayed instead is:

which isn't exactly what I had in mind.
I opened the file in
Notepad++ (my text editor of choice) to take a look at the file type and it is, as I'd expected, saved as ANSI, not UTF-8 or UTF-16

I used Notepad++'s menu item Format -> Convert to UTF-8 to convert this file from ANSI into UTF-8, and then re-ran my test and all works correctly as expected. Hurrah!
I then repeated this using VS2008 and found that this is one of the fixes over VS2005.
So, the alert now correctly displays:

and when opened in Notepad++ the file is now, correctly, UTF-8.

Labels: javascript, localisation, localization, Visual Studio
// posted by Jane @ 3:43 PM
Comments:
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:
- Basic - 2 javascript files, one per language - duplicate functionality
- Literals - 3 javascript files - one per language, plus one with functionality
- 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
- 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: ASP.NET, javascript, localisation, localization, resources
// posted by Jane @ 7:47 PM
Comments: