NxtGen Coventry: 10 Things To Know Before Internationalizing An Application (Slides)

Thanks to everyone at Next Generation User Group for their hospitality last night and for making the evening such a fun and interesting one. The slides for the 10 Things To Know Before Internationalizing An Application are here.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Tuesday, March 20, 2007 at 10:20 PM
Categories: Events
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

New User Group - The .NET Developer Network

The UK has a new user group, The .NET Developer Network (http://www.dotnetdevnet.com). The .NET Developer Network is a free user group based in Bristol (England) that serves .NET developers in the South West of England. The aim is to develop and promote the .NET developers, architects and IT pros of Bristol and the South West. Through monthly meetings we expect to generate a lively community and act as a focal point for the professionals of this area.

The first meeting is on Monday 23rd April 2007 (St. George’s Day) and features a whole evening with Mike Taulty (Microsoft Developer Evangelist) giving two sessions on LINQ:-


  • Introduction to Language Integrated Query – Language Changes in C# 3.0 and VB9 that facilitate LINQ

  • LINQ and Advances for Data Access


More details available here. To attend you need to be a member (it’s free, just register) and then sign up for the meeting (see the details on the site).

Come down to the first ever .NET Developer Network meeting and be able to tell people that you were there at the very beginning.

See you there!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Tuesday, March 20, 2007 at 10:18 PM
Categories: Events
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

Extending The CultureInfo Class Using Extension Methods

In chapter 6 of .NET Internationalization I wrote a section entitled "Extending The CultureInfo Class". I showed how to inherit from the CultureInfo class and fix the Parent and InvariantCulture properties so that they returned the subclass and the subclass behaved correctly (you can download the source code for the CultureInfoEx class here). In this post I show how to achieve the same result using an alternative approach: Extension Methods. There are two goals behind this post: (1) show how to extend the CultureInfo class and (2) illustrate why Extension Methods are worth taking a good hard look at.

Extension Methods are a new feature in the .NET Framework 3.5. They are often overlooked as a necessary part of enabling LINQ (Language Integrated Query) but they are a profoundly useful feature in their own right. To make use of Extension Methods you will need to download LINQ:-

http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx

An extension method is a method that is added to an existing class without having to recompile the original class. The immediate benefit of this feature is that you can extend classes that you do not have the source code to. The CultureInfo class springs to mind. Here’s an example of how to extend the CultureInfo class using extension methods:-


// ExtendingCultureInfo.cs
using System;
using System.Globalization;
using System.Runtime.CompilerServices;

public class ExtendingCultureInfo
{
static void Main(string[] args)
{
CultureInfo cultureInfo = new CultureInfo("en-GB");
Console.Write(cultureInfo.DisplayName + ": ");
// displays "Invoices"
Console.WriteLine(cultureInfo.ToPlural("Invoice"));
}
}

static class CultureInfoExtensions
{
[Extension]
public static string ToPlural(this CultureInfo cultureInfo, string singular)
{
if (cultureInfo.TwoLetterISOLanguageName == "en")
// English
return singular + "s";
else
return singular;
}
}

To compile this example open up a .NET Framework 2.0 command prompt and using the LINQ C# compiler (not the .NET Framework 2.0 compiler) execute the following line:-

csc ExtendingCultureInfo.cs /reference:"C:\Program Files\LINQ Preview\Bin\System.Query.dll"

The CultureInfoExtensions class includes a static method called ToPlural which converts a singular word to a plural word. (The algorithm represented here is simplistic in the extreme and is intended as an example as opposed to a realistic implementation). This static method accepts a CultureInfo parameter which is qualified with the "this" keyword. This parameter is passed by the compiler and is a reference to the object that the method was called on. The existence of this parameter explains why there is no such thing as Extension Properties. Also note that the ToPlural method is decorated with the Extension attribute to mark that the method extends another class. When the new method is used by an object it is referenced in the same way as a built in method without any special syntax required by the extension method.

So why is this so clever ? It is clever for a number of reasons. First, as I have already mentioned you do not need the original source code to extend a class and therefore this is very relevant for all classes that are part of the .NET Framework. Second, you can extend sealed classes and as I am not a big fan of sealed classes this makes me happy. Third, and this is the defining point, you do not need to be in control of the code that creates a new object of the class you want to extend. Think about this: if<

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Monday, March 12, 2007 at 8:41 PM
Categories: Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

Custom Cultures, Vista and the IetfLanguageTag

One of the great features in the .NET Framework 2.0 is the ability to define new or replacement cultures, known as custom cultures. One of the benefits of this feature is that it allows you to export cultures from newer operating systems to older operating systems. This allows you to reap the rewards of the new culture without having to upgrade. The exported cultures are not always an exact replica of the original (for example the target operating system may not support the sort orders required by the exported culture) but it is often better than forcing your users to upgrade. I cover the subject of Custom Cultures in depth in one of the free sample chapters for .NET Internationalization.

The purpose of this post, however, is to explain why it is not so straight forwards exporting cultures from Vista as it is for other operating systems and what you can do to overcome this difference.

The problem lies in the ieftLanguageTag. The ietfLanguageTag is the culture name formatted according to the RFC 3066 standard. It is relevant because the CultureAndRegionInfoBuilder (i.e. the class that builds custom cultures and can ’export’ them) does not save the ietfLanguageTag when it runs on Vista. If you export the English (United States) ("en-US") from Windows XP SP2 and look through the generated LDML file you will find the following line:-

msLocale:ietfLanguageTag type="en-US"

If you do the same from Vista the line won’t be there. This is a problem because if you try to load the resulting LDML file in an older operating system an exception will be thrown and the culture will not be imported. Now naturaly there is no value in exporting the English (United States) culture because all operating systems include this culture but you can see that this is a problem if the whole reason for doing this is to export a Vista culture to Windows XP SP 2.

So the solution to the problem is to add the ietfLanguageTag element back into the LDML file:-

public static void SetIetfLanguageTag(string ldmlFilename, string ietfLanguageTag)
{
const string msLocaleNamespace = "http://schemas.microsoft.com/globalization/2004/08/carib/ldml";

// Vista is version 6
if (System.Environment.OSVersion.Version.Major >= 6)
{
XmlDocument xmlDocument = new XmlDocument();
using (FileStream fileStream = new FileStream(ldmlFilename, FileMode.Open))
{
xmlDocument.Load(fileStream);

XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
xmlNamespaceManager.AddNamespace("msLocale", msLocaleNamespace);

// Check to see if the LDML file is missing the IETF Language Tag.
XmlNode ietfLanguageTagXmlNode = xmlDocument.SelectSingleNode(
"//identity/special/msLocale:ietfLanguageTag", xmlNamespaceManager);
if (ietfLanguageTagXmlNode == null)
{
// the IEFT Language Tag is missing - add it back
XmlNode msLocaleXmlNode = xmlDocument.SelectSingleNode(
"//identity/special", xmlNamespaceManager);
if (msLocaleXmlNode is XmlElement)
{
XmlElement ietfLanguageTagXmlElement =
xmlDocument.CreateElement("msLocale", "ietfLanguageTag", msLocaleNamespace);
ietfLanguageTagXmlElement.SetAttribute("type", ietfLanguageTag);
msLocaleXmlNode.AppendChild(ietfLanguageTagXmlElement);
}
}
}
xmlDocument.Save(ldmlFilename);
}
}

Call this me

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Friday, March 09, 2007 at 9:26 PM
Categories: Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (4) | Post RSSRSS comment feed

Flipper Flopper Machine Translation

Microsoft are piloting a program for translating MSDN articles using machine translation. Called Flipper Flopper it offers a choice of 1 of 6 languages in which to view a .NET Framework 3 or Vista MSDN article in both English and a machine translated equivalent in your chosen target language. Machine translation is hardly ever perfect and occasionally it is awful to the point of amusing but this step by Microsoft shows that there is enough belief in making a credible attempt at this to give it a try. Based on my limited ability it certainly looks like the machine translator in question has done as reasonable a job as you could expect using today’s technology.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Monday, March 05, 2007 at 9:18 PM
Categories: Internationalization
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

The NxtGenUG Vista ReadyBoost Song By Dave McMahon

Witness a piece of history: Dave McMahon sings the Vista ReadyBoost song at the NxtGenUG Vista Launch this week. Inspired! You can listen to it here.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Saturday, March 03, 2007 at 8:37 AM
Categories: Events
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

GotDotNet Being Phased Out

The once revolutionary GotDotNet (http://www.gotdotnet.com) is being phased out. GotDotNet used to be the hub of the .NET industry and a site that I visited every day. Now, after drastically reduced traffic over the last 6 months and duplication of content and functionality with other Microsoft sites GotDotNet is being phased out and will be gone entirely by July 2007. Much of the content (including FxCop) will be moved over to MSDN.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Guy Smith-Ferrier
Posted on: Thursday, March 01, 2007 at 9:22 AM
Categories: Miscellaneous - Technical
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed