views:

165

answers:

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?)

+2  A: 

Hi,

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.

kervin
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
+1  A: 

.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".

Greg
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
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
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
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
A: 

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


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.

Toby