Subscribe to the RSS feed then follow me on twitter at @mrlacey (misc) and @wpug (WPDev news)

Friday, March 08, 2013

NCLDR on Windows Phone 8

Earlier this week, uber-UK-community-bod and I18n expert, Guy Smith-Ferrier announced the alpha launch of NCLDR.

If you're not familiar with CLDR you can think of it as being like a version of the Globalization parts of the .net framework with lots of added extras. NCLDR is a .net port that allows access to all these lovely goodies.

As is my way and because I was interested if I could use the data in a phone app so I attempted a port/conversion to Windows Phone 8. It's just a POC at the moment, but look, I can get a regex for validating postcodes for each (well most) supported culture(s). If you're capturing a postal or zip code in your app this would allow you to validate it on the device, regardless of which country it was in.


I'll be honest, it wasn't as simple as I'd hoped. There was a lot more work and work arounds needed to get it to work than I would have liked and if Windows Phone support was to be officially added it would be better to add it in early and maybe remove use of some of the types and methods which are not supported on the phone, to aid greater cross platform code reuse.

Here's the changes I had to make to get it to work:

Biggest issue: WP doesn't support BinaryFormatter.
Second but related issue: By switching to using a JSON serializer I was potentially making the data file even bigger. I countered this by only including the minimum I needed in the generated file. This no only made the data file smaller but meant I had to load less and so save on precious memory consumption.

Add missing System elements:
  • CultureTypes
  • DigitShapes
  • ICloneable
  • SerializableAttribute
Replace use of HashTable with Dictionary<string, string>. In:
  • Culture.cs
  • Numbers.cs

Replace verison of string.Compare that was used with a WindowsPhone supported version. In:
  • Calendar.cs
  • CultureData.cs
  • Currency.cs
  • CurrencyPeriod.cs
  • Language.cs
  • MessageSet.cs
  • NumberingSystem.cs
  • NumberingSystemType.cs
  • Numbers.cs
  • PluralRule.cs
  • Region.cs
  • RegionMeasuringSystem.cs
  • CultureInfoExtensions.cs
  • RegionInfoExtensions.cs


Added some null exception handling/wrapping/suppressing to the following (but didn't really look into why it was needed):
  • Language.cs
  • Calendar.cs
  • Region.cs
  • CurrencyPeriod.cs
  • NumberingSystem.cs
  • Script.cs

Hopefully unnecessary disclaimer: This is a quickly hacked together proof of concept on top of alpha code. Use at your own risk...




Are you a Windows Phone, Nokia-X (Android) or Asha developer? If so, you could be getting rewards for the apps you build and the success they achieve by joining the DVLUP program.

4 comments:

  1. Great work, Matt. Thanks for the listing of issues you faced in getting this working with WP8.

    The BinaryFormatter will become optional and you will get control of how you serialize/deserialize in a near future release.

    All of the Hashtables will be replaced with another structure/class.

    Can you email me the string.Compare that you had to use and I will think about a possible solution ?

    The null handling problems will get resolved soon. Full testing with cut-down versions of the .dat file is not complete yet.

    Thanks again, Matt. This is really helpful for me.

    Guy

    ReplyDelete
  2. Hi Matt,

    Just so you know version 0.0.0.004-Alpha (released today) fixes most of the issues that you had using a cut down NCLDR with Windows Phone 8. Work in the area of making NCLDR usable with Windows Phone 8 doesn't stop with this release. Support will improve in future releases.

    Guy

    ReplyDelete
  3. Hi Matt,

    Version 0.0.0.005-Alpha was released today and this fixes the remaining issues you were having. NCLDR now offers a choice of data file formats (binary, JSON, XML) where only JSON and XML are available on Windows Phone.

    Thanks for your help with this.

    Guy

    ReplyDelete