We got some queries on our recent blog on with suggestions on using the database to store the localized strings files rather than the default resx approach. We pondered over it, then pondered some more and came to the following conclusion…
The challenge we are tackling here is of white labeling and not just localization. i.e the clients may want to change the text on controls and Labels and not that “Product Company” would want to keep changing the default text. So the issue is “customization” and not “Frequent change”
Approaches to Localization
Database to store localized strings
- Can edit/add the localized text without compilation
- Strain on DB server as all data localized text needs to be loaded from the DB
- Testing overhead when creating the screen layout and controls which suits various languages
- Binding Label and control texts will be more cumbersome( Though possible via some packages like WestWind.Globalization)
Using Resx files
- Standard way of working with Resx files and supported by framework. Can create default Global application resources as well as file level resources like Sample.aspx.fr.resx
- Lesser performance overhead since strings are compiled within the dll
- Direct binding with control and label texts
- Easier testing by simply defining the resources, binding to controls and changing browser language settings. (See https://msdn.microsoft.com/en-us/library/fw69ke6f%28v=vs.140%29.aspx?f=255&MSPPError=-2147217396)
- The resources need to be recompiled into the app if changed.
Suggested Way by the Industry
- Use resx files for strings that do not change frequently and database for strings that change frequently
- Check ALL comments in the following post (http://channel9.msdn.com/Forums/Coffeehouse/250892-Localizing-with-a-database-or-resx-files)
- Also see http://www.mikesdotnetting.com/article/183/globalization-and-localization-with-razor-web-pages.
Note the following conclusion at the end
‘You have seen two approaches – Resource files and database. Resource files compile to dlls when the application first runs. For this reason, they are best used for content that changes infrequently. Since they are easiest to work with when you have specialist tools, they are not suitable for storing user-provided values. Databases are better for user-supplied content and that which may change on a regular basis.’
Suggestion from Cennest for the current problem statement
- Use Resx files per language to create store the localized strings for your default texts. This will allow you to
- Speed up development and testing time
- Ensure the DB is not strained
- Performance of the app is optimum for the default happy path
- If the customer customizes the text for a control then store the customized value in the DB
- During Page load, load the page from the resx file. On background thread load the custom values provided by the customer and override the resx value.
If you do use the Database as a way to store all your resource info , you can try using some of the newer libraries like WestWind.globalization to help you manage your DB more easily . It works well with MVC also and has some inherent caching to save you DB hits. More info here (http://www.west-wind.com/westwind.globalization/)
Look forward to hearing some more thoughts on this!