Need advice on localizing ASP.NET - strings stored in the database and displayed in gridview

I am looking for some localization tips. I have an application that was localized in the usual way (i.e...resx files) that processes about 95% of the lines. However, I still need to localize some strings for the category names that are stored in the database.

I would like to add 15 new columns with the name categoryname_ES, categoryname_FR, etc., and then dynamically pull the right column. If there is some way to pull the data and then make a replacement in the code, I think it will be a little less messy. Possibly line by line:

  • go through gridview row by row
  • If the selected language is not English, find this text value in the global resource file and replace it.

Does anyone have a good idea on how to do this? Or adds a lot of category columns for each language to go through (ewww).

+4
source share
3 answers

I am using the resource file method that you are describing.

  • Add a CategoryName.resx file with a line for each category. Make sure the "Name" exactly matches your database value. Put the translation in "Value".
  • Get the line in the code through the generated resx code file. (sorry C #) Resources.CategoryName.ResourceManager.GetString(categoryName, new CultureInfo("fr"));

If you bind to a custom class, just create another property and bind it to this property. If you bind to a DataSet, you can use the RowDataBound event to substitute.

+3
source

You can do this with four database columns:

 ID (unique primary key) CultureCode ProductID ProductName 

I assume that you select your products from the database. Go into the UI culture as part of the stored procedure, then when you select from your product table, join the Culture table on the product ID and UICulture. You would call your SELECT as follows:

 SELECT ProductID ,another field ,IsNull(Culture.ProductName, Product.ProductName) ,etc FROM Product LEFT JOIN Culture ON Product.ProductID = Culture.ProductID AND Culture.CultureCode = @UICulture 

you get the idea. You can even check the UICulture for the hyphen (for example: fr-CA), split it into another variable, then make two connections in the Culture table - one for the exact culture and one for the backup culture, so in this example the first connection will be for fr-CA and the second connection will simply be dropped before fr. If your entire culture is combined with an error (for example, because you do not have Zulu in the culture table), IsNull uses only the regular ProductName (this may be in English).

+3
source

You can create three tables:

 Category Category_ID (identity) Category_Name (string) Language Language_ID (identity) Language_Name (string) CategoryLanguage Category_ID (FK) Language_ID (FK) Translation (string) 

The category table will have names in English. The language table will contain the languages ​​supported by your application. The association table can then provide the name of the translated category based on the selected language, if one exists. If it does not exist, just show the default English version.

+1
source

All Articles