Jason Salas' WebLog

On-air and online: making people laugh, making people think, pissing people off

Sponsors

ASP.NET sites that kick ass

Pals with blogs

Podcasts I listen to

Can new cultures be added to System.Globalization.CultureInfo?

I mentioned in a previous blog about a new project I'm working on to allow for bilingual support for the content on some areas of my station's site.  Well, now in addition to supporting Guam's native Chamorro language, I've added Tagalog, the dominant dialect used in the Phillipines, to the project spec. 

After trying to mentally organize the methods I'll need in the various namespaces and thinking about preparing the resources files, the requirement for UTF-8 to account for encoding for international characters sets and accent marks, I thought it had it down. 

After letting my “architecture“ sink in during a long pre-Super Bowl XXXVIII nap, I realized that it might not be as easy as I thought.  I'm unsure at this point if I'm going to be able to extend the CultureInfo class to include date and number formatting considerations for each new language, as neither is provided out-of-box.  I naively thought the set of cultures and formatting, encoding, and character sets accompanying them provided by CultureInfo were specific to the .NET Framework, but now I'm hoping it's not an MSIE-specific thing, or worse, a W3C standard, although I know the language codes derive from ISO.  I'm just postulating all this now, without researching (which is my big problem).

Hopefully, I'll be able to define and add new languages (or figure out some effective alternative) and get this up and running.  Otherwise, it's going to be some looooong nights...

Comments

Christian Nagel said:

Jason,
Read my weblog entry and sample about extending CultureInfo. I've done a sample to create a Klingon culture (et-Klingon):
http://weblogs.asp.net/cnagel/archive/2003/07/06/9753.aspx
http://weblogs.asp.net/cnagel/archive/2003/07/06/9751.aspx
http://weblogs.asp.net/cnagel/archive/2003/07/06/9750.aspx
# February 2, 2004 1:39 AM

Jason Salas said:

Thanks much Christian! I was gonna mess with Pig Latin as a sample project, but I'll check out your stuff. :)
# February 2, 2004 4:09 AM

TrackBack said:

# February 2, 2004 5:19 PM

Jason Salas said:

Here's the actual code for extending the CultureInfo class Christian mentioned in his reply above (thanks, Christian):

using System;
using System.Resources;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using System.Globalization;
using System.Diagnostics;

namespace Nagel.Demos.Enterprise
{

// derive from CultureInfo, so it can be used as a CultureInfo
public class EnterpriseCultureInfo : CultureInfo
{
private string name;
private string displayName;

public EnterpriseCultureInfo(string extendedCulture) : base("en-US")
{
if (extendedCulture != "et-klingon" && extendedCulture != "et-vulcano")
throw new NotSupportedException("The culture " + extendedCulture + " is not supported");

name = extendedCulture;

switch (extendedCulture)
{
case "et-klingon":
displayName = "Klingon";
break;
case "et-vulcono":
displayName = "Vulcano";
break;
}
}

#region Overridden properties of CultureInfo
public override string DisplayName
{
get
{
return displayName;
}
}

public override string Name
{
get
{
return name;
}
}

public override string EnglishName
{
get
{
return displayName;
}
}
#endregion

// also needed for a full implementation: date/time format, Klingon calendar, number format...

}

}
# February 3, 2004 7:19 PM

Jason Salas said:

**UPDATE**

A Microsoft PM that owns the Globalization subset of the ASP.NET feature set was nice enought to point me to a working sample of how to add new custom cultures in order to tap into resource files: http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=a193b952-2e44-45ed-811d-c1fabf2f6e8a
# February 21, 2004 12:28 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)