Localization with NameValueList

Localization with NameValueList

Old forum URL: forums.lhotka.net/forums/t/1255.aspx


Gort posted on Monday, September 18, 2006

I am wondering about the suggested way to handle the following scenario:

We have dropdownlists that are populated from our database via the NameValueList class.  We also are implementing localization on our site, so is there is a recommended method for changing the value of the string for the dropdownlist?

So, if our dropdownlist has the items 'Public', 'Private', and 'Other' (each with their own ID value), how would I update those values for, say, a French user?  The lookup table that I am referring to above is a foreign key for another table, say 'Company'. 

We were thinking of putting a pseudo string in the database, like 'Company_Private'.  Then, replacing this string within the NameValueList with the actual resource string.  Not sure if this is the best approach though.

Thoughts?

Thanks for looking...

Henrik replied on Monday, September 18, 2006

Gort

You could put the resource key string into the database and then do a replacement when you display the valuelist. However, this reduces your extensibility. If you ever want to add other types to the database, you'll have to at least add the new values to your resources files and recompile these or at worst recompile your entire application if the resources aren't in satellite assemblies.

Another way of solving this is to create a localized string table in the database and store the different language representations of your strings in this and have a foreign key from your lookup table. The table could look like this:

Table: Strings
StringId   Int Identity
Culture    varchar(6)
String     nvarchar(256) null
LongString ntext null

The stored proc, that retrieves your lookup table values will need the culture code (en-US/da-DK/other) and make a join with the Strings table. You'll be able to use this for other tables that must be localized as well.

This, however, is a lot more work and you'll get a small performance penalty from the join. This approach will work both for static values (values that you define as a developer) and for user defined values (values created by the user).

There is one catch, though. The user created strings stored in the db will be in the language that the user speaks, meaning that if an english speaking user is entering a description of something, say a road direction, this will only be stored in the english version unless you provide the user with a UI where he/she can provide a string version for every language your app supports and the user is capable of translating the string into all these languages, which is unlikely.

I come from Denmark and we are only about 6 mio people speaking the danish language in the world, so I've come across localizing applications more often than not. What I found is that the above-described method is great for static (developer defined) strings, but it's almost impossible to create an application where user defined strings are localized as well. Even if users are capable of describing strings in 10 different languages, nobody would want to do this. So I've come to a manual solution, where I instruct the users to write their strings in english, if they know that it will be seen by users speaking other languages (just like this messageboard, where everything is in english).

Hope this helps

/Henrik

Gort replied on Tuesday, September 19, 2006

I do not want to store any resources in the database.  I want all my resources stored in one location, the resource files.

Henrik replied on Wednesday, September 20, 2006

Then you should follow the approach you suggested by storing the resource key strings in the lookup table and replace these in your fetch method like so:

Private Overloads Sub DataPortal_Fetch(ByVal crit As Criteria)

  

   Using dr As New SafeDataReader(cm.ExecuteReader)

      If dr.Read() Then

          With dr

            _value = My.Resources.ResourceManager.GetString(.GetString("Value"))

           

          End With 

      End If

   End Using

  

End Sub

 

/Henrik

 

Gort replied on Wednesday, September 20, 2006

OK, I'll look into implementing things that way then.  Thanks for checking out my post and giving me some feedback.

Copyright (c) Marimer LLC