Need advice on ASP.NET localization - strings stored in a database & displayed in a gridview
asp.net, localization, vb.net
Solution
I use the resource file method that you describe.
- Add a CategoryName.resx file with a row for each category. Make sure the "Name" matches your database value exactly. Put the translation in the "Value".
- Get the string in code via the resx's generated code file. (sorry for the C#) `Resources.CategoryName.ResourceManager.GetString(categoryName, new CultureInfo("fr"));`
If you're binding to custom class, just make another property and bind to that property instead. If you're binding to a DataSet, you might want to use the RowDataBound event to do the substitution.
Problem
I am looking for some advice on localization. I have an app that has been localized in the usual fashion (i.e., .resx files), which handles about 95% of the strings. However, I still need to localize some strings for category names that are stored in the database. I'd like to avoid adding 15 new columns named categoryname_ES, categoryname_FR, etc, and then pulling the right column dynamically. If there would be some way to pull the data, and then do a substitution in the code, I think that would be a little less messy. Maybe along the lines of: - go through gridview row by row - if the language selected isn't english, look for this text value in a global resources file and replace it. Anyone have a good idea of how to accomplish this? Or is adding a lot of categoryname columns for each language just the way to go (ewww).