views:

105

answers:

3

I'd like to externalize all of the strings used in the project into one file and be able to use it inside aspx, C# code behind and on the client side in JavaScript.
The reason I want to do it is because many strings are shared, i.e. the same in two places.

Is it possible? Is there a better way?

A: 

Sounds like it's right up XML's alley....

Mark Brackett
+2  A: 

JSON is a good fit - a similar question: How do you share configuration information or business rules between languages

Ken
+1  A: 

One answerer suggested XML, but that would be very heavyweight for shipping to to the client.

Consider doing something similar to the mini-fication process of javascript. Take your strings that you are using on the server/C# side and process your javascript files using something like perl/python/ruby, replacing the ids of the strings with the strings themselves.

So, if your javascript says:

alert($MY_TEXT$)

it gets changed to

alert("The string associated with $MY_TEXT$")

The perl/python/ruby process takes place in your "build" of the javascript files, before deployment to your production servers.

Corey Trager