1

We have a large localized ASP.NET MVC 4 site and we are struggling to manage the resource keys. What we have at the moment is a series of partial static classes containing constant values such as the following:

public static partial class Resources { public static class News { public static class Shared { public const string Title = "News_Shared_Title"; } } } 

This allows us for example to call the following:

<%: Html.Resource(Resources.News.Shared.Title) %> 

On a view which passes the key "News_Shared_Title" to our database resource implementation.

The problem with this is it slows down development having to stop and manage the static classes whereas it would be much faster to for example just type:

<%: Html.Resource("News_Shared_Title") %> 

The problem with this approach is that it is harder to manage, possible typos and we also lose the ability to have an application that uses reflection to get all the key values from the static resource classes and see which are missing from the database.

My question is how do other people manage their resource keys and is there a better approach? If we went with strings on the views/controllers/etc. how would we get all the keys within an application and see which are missing from the database?

2
  • Why don't you use resource (resx) files? Commented Dec 20, 2013 at 10:50
  • Can't you generate the source files from the data in the database? You'd probably have to make a script or little tool to do this. But that way you only have to maintain the database. Commented Dec 20, 2013 at 13:13

1 Answer 1

0

Why not using Resources files ? (resx) Shouldn't it be better ?

Create a new project in your solution with your resx files only and then add it as a reference in your main project. Then use a custom namespace for the resources project to be more readable on your main project.

EDIT:

It's really powerful depending on name of the resources file if your CurrentCulture is set properly it will automagically pick the right resx file. More infos here : http://msdn.microsoft.com/en-us/library/ms247246(v=vs.100).aspx

Don't know if it answers your question :)

Sign up to request clarification or add additional context in comments.

3 Comments

There are a multitude of reasons we don't use resx files but the main ones are the ease of exporting data from the database with keys and english, having it translated by external translation services and simply reimporting to a master database that is maintained and source controlled.
If the main concern is managing the translations and sending the texts to your translators, then maybe check out this question too: stackoverflow.com/questions/20324967/…
This is an interesting idea and I'll have a look into it, thank you for the suggestion. The main problem I see is managing such a large number of keys/translations as we have which would be too big or one file so we would want to split the resources up for different controllers, areas, etc. Could be a lot to manage whereas with the current static class/DB solution we create different static classes for logical separations. I guess there is no one best solution, it's pros and cons.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.