Welcome to FairlyLocalIt's a simple Internationalization (i18n) library that makes ASP.NET websites work with GNU's GetText tools. It's the way that i18n should have worked from the start.
<%= _("Buy more socks.") %>Here's how you'd do it in a .cs (or .aspx.cs) file:
linkHome.InnerHtml = _("Home Page");That's it. That's all the code you need to write on a day-to-day basis to localize your site. Everything else is handled by the FairlyLocal library that you'll drop into your project, and by a few free tools that you can download from the nice folks at GNU.
How it worksGettext() works by sifting through your source code and generating .PO files at compile time. .PO is a simple text file format for storing messages and their translations that's basic enough to be edited in notepad by non-tech-savvy translators, but is popular enough that there are several existing editors built just for it. Once those .PO files are in place and translated, FairlyLocal will read them in and keep them cached in memory on your web server. Whenever a request for a piece of text comes through, the library will look it up in the appropriate language hash, handing back the translated version of the text if possible, or an untranslated version if not. The nice thing about all this is that you don't need to specify keys for each piece of text. Gettext uses the entire English text string as its own key for lookups. What if that text changes? No worries. A lot of smart people have spent time dealing with fuzzy match algorithms to keep your translation files in synch in the face of minor changes. It's actually pretty cool. FairlyLocal figures out which language to show based on the language preference settings in your users' browser. If you'd like, you can manually change the display language for a user, so you could, for example, include some little flag icons on your site that your users can click to select his language of choice.
Setting it up
February 22, 2010 by Jason Kester