BlogEngine.NET Custom Resource Provider & Visual Studio regex find + replace

I am currently working on a project which is requiring me to turn BlogEngine.NET into multi-language website CMS / Blogging Platform. I plan on adding at least one more post detailing some of the major steps I took to make "dynamic translations" possible with BlogEngine.NET, but that post will have to wait for another day.  This post is all about implementing a custom asp.net resource provider into the BlogEngine.NET platform.

One of the first things I did was take a look at some existing examples of customized resource providers for asp.net.  Most notable among these is the implementation provided, and nicely documented, by Rick Strahl at West Wind Technologies.  This provider has been available for download for a few years now but this has been my first opportunity to take a look under the hood.  I would strongly recommend you at least download the source code that Rick has made available, if for nothing other than a nice starting point for your own implementation.

I should also mention that it might be a good idea to read over Extending the ASP.NET 2.0 Resource-Provider Model article on msdn as well. 

I ended up creating a resource provider based on the Rick Stralh SimpleDbResourceProvider implementation.  I had no need for localizing non-asp.net resources, so a simple provider model using SQL was suitable to the project needs.

The major modification I had to make to BlogEngine.NET was the replacing of all the "Resources.labels.labelnamehere" instances scattered throughout the app.  I believe there was 244 or so (estimated).  To do this I turned to Visual Studio and it's regular expression find & replace mechanism.  It was a tad wierd to get working just right as visual studio uses it's own regular expression syntax.  You can read up on it here and here.

The Find expression I used:

<Resources\.labels.{[a-z]*}

And the replace expression I used:

((string)HttpContext.GetGlobalResourceObject("labels", "\1"))

The outter brackets that contain everything allowed some of the blogengine code that used string extension methods to still function.  For example, Resources.labels.name.ToUpperInvariant() would become ((string)HttpContext.GetGlobalResourceObject("labels", "name")).ToUpperInvariant().

Hope this helps someone out there!