Reputation: 2860
I'm trying to do localization in MVC3, and I want to use a database to store the resources. I've read up on resource providers, but I haven't found a way of using a resource provider without losing the strongly-typed access that a regular resource file has.
So, what is the best way to do localization, while maintaining strongly-typed access? (Ideally with a database too)
Upvotes: 0
Views: 403
Reputation: 1673
The simple and effective way to do it, is just to use the NuGet package dedicated for storing resources in database and generating the Strongly Typed Resources.
NuGet Package: http://www.nuget.org/packages/Globsite.Globalization.Mvc
Project Site: http://globsite.net/GlobsiteGlobalizationLibrary
This package contains the ready to use and complex infrastructure for database stored resources, which implements .NET Resource-Provider Model. Generated classes can be synchronized with a database with the T4 Template run, what can be done, for example, on each build.
You can use the resources like this:
@using MyResources.SampleSet
@Resources.SampleKey
Upvotes: 0
Reputation: 39898
If you want to store the entries in a database you can do the same trick as the normal resource files in Visual Studio are doing for you.
Normally the resource file is parsed and a static class is generated from it. In your case you could us a T4 template(Code Generation and T4) to connect to the database and build a resource class from the 'Id' columns in your database you have the same resource class.
On startup you could load the translated strings from the database and initialize your T4 resource class with it.
Upvotes: 1