3

I am writing a web app in ASP.NET (2.0), VS2005. The main reason for developing a new application (rather than using readily-available off-the-shelf solutions) is that I need full support for at least two languages (that is front-end and the data). I am looking for the best ways of tackling i18n in ASP.NET (it can be just the UI, sorting out DB is simpler). Obviously .NET provides its own i18n mechanisms and I've been using those before but have not been greatly impressed - it falls short in my opinion to gettext that I used on a few big open source projects in C++ and Java. I am looking for a solution that would satisfy the following requirements:

  • all translations gathered in one place
  • adding new languages being easy
  • translating does not require VS and can be done by fairly inexperienced users (translators)
  • discovery of available languages
  • changes to original strings easily cascaded to existing translations
  • support for plural forms (ngettext)

(any more ideas?)

5 Answers 5

6

I am not sure what you have against regular Globalization and Localization, which you've said you've used already.

.Net localization has worked great on the projects I've used it for without modification of the core principles. How exactly has it fallen short for you?

For example, the features you've listed can be done with the ASP.Net Globalization Framework.

  • All your translations are gathered in your resource ( .resx ) files. Which can be inserted in a single or multiple assemblies.
  • Adding a language is as easy as adding a resource file with the proper culture prefix. This again can be a separate file or an embedded resource.
  • Translation does not require Visual Studio depending on your scenario. Resource files ( .resx ) are XML files. You only need to recompile if you embed your resource files.
  • language discovery is supported, "cascading" translations is supported.
  • Plurals may have to be dealt with using logic, but that seems like an easy fix.

Finally, if none of this suites you, then you can Extend the Resource Provider Model to get your localization text from any source that you choose.

1
  • 1
    Thanks. All valid points. What has usually fallen short for me was adding new resource files and synchronising the strings with the original list. Also the fact that you need to assign a 'key' to every string is not helpful (and this is where people ask for sane naming conventions). Plurals are a big one for me (many: "you have selected 1 item(s)") and they are really tricky with some languages (you sometimes need 3 forms).
    – mfloryan
    Jun 29, 2009 at 21:50
4

A quick note: gettext can apparently be used as an unmanaged library on Win32 platforms. Check out this dude's blog post:

http://weblogs.manas.com.ar/spalladino/2009/10/07/gettext-i18n-strings-in-asp-net-controls/

Also, from the gettext languages documentation on C#:

http://www.gnu.org/software/hello/manual/gettext/C_0023.html#C_0023

And another one talking about gettext i18n for asp.net:

http://www.expatsoftware.com/articles/2010/03/fixing-internationalization-in-aspnet.html


Opinion continues: I really think the .NET style internationalization-using-resources-file is not so good. First off, you have to write your strings in code:

My.Resources.ErrorMsgDbNotConnected

Before your code will compile, you have to add the string to the resources file. Jumping from what you're working on to go add a string to a resources file and then coming back is a hinderance, if you ask me. Also, the inverse is true: to find the string, you need to look in the resources folder. Less drastic, but still annoying.

gettext uses your home-language strings as keys:

gettext("Sorry, the database connection could not be created.")

If there's no key in the language file, the original string is parsed and used. Also, this means that a translator only needs to have one file open to see the original language string and the translated string, rather than opening and comparing two resource files.

gettext also has support for plurals, gender, and other language variations, so it can fix pluralization problems ("You have 1 new emails.") even in English!

Don't think I'm a .NET hater: the .NET calendar, time, and number formatting based on culture is really excellent, I just find the translation stuff to be a bit lacking.

1
  • I also recently noticed that you don't need to link to the gettext unmanaged dll; there is a C# implementation available from the gettext site. I believe it extends existing .NET translation code.
    – Toby
    Aug 18, 2011 at 22:53
2

Check out FairlyLocal. It's a GetText-based i18n library for ASP.NET, and it's pretty much exactly what you're asking for.

Way better than dealing with giant .resx files and wrapping all your text in server controls.

1

.Net already supports adding new languages easily and discovering what languages are available.

To address the requirement of editing without VS and having all resources gathering in one place:

If you want to use the built-in .net framework to localize, I'd recommend using Zeta Resource Editor to edit your resource files. Zeta has some nice features, like marking resources that don't have all of the proper translations and also marking resources where the formatting characters (e.g. {0} {1} ) don't match up.

If you want something more centralized, take a look at creating a database resource provider.

Unfortunately support for plurals is non-existent.

I don't know what you mean by "changes to original strings easily cascaded to existing translations".

4
  • 1
    What I have experienced with .NET is that once new strings are added and changed - you have to make sure they are cascaded to all the resource files. Unless I am missing something you have to do it manually or use a third party tool.
    – mfloryan
    Jun 29, 2009 at 21:46
  • You can use Global resources for resources that are shared across multiple pages. So you could have an ErrorMessages resx that has all of your error messages in it.
    – Greg
    Jun 30, 2009 at 13:41
  • 1
    Yes, that I already did. But my point is - that if I add a new error message to the main resource file I then have to go and add it to all the other resource files.
    – mfloryan
    Jul 1, 2009 at 13:11
  • Do you mean the other resource files for the other languages? Like ErrorMessages.fr.resx, ErrorMessages.es.resx...etc. Zeta Resource Editor makes that a lot nicer. If you don't mean that, I'm not sure what you're talking about. :-)
    – Greg
    Jul 1, 2009 at 13:39
0

For plurals and genders you can use

https://github.com/jaska45/I18N

It uses rules from CLDR without needing CLDR's XML files or ICU's DLL. Eveything (logic and rules) are implemented as C# files of the library. Very easy to use.

var message = MultiPattern.Format("one;I have {0} car;other;I have {0} cars", cars);

When localizing the translator can provide as many patterns as the target language requires.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.