2

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?

z-boss
  • 17,111
  • 12
  • 49
  • 81

3 Answers3

2

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

Community
  • 1
  • 1
Ken
  • 77,016
  • 30
  • 84
  • 101
1

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

Consider doing something similar to the minification 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.

Alex
  • 1,457
  • 1
  • 13
  • 26
Corey Trager
  • 22,649
  • 18
  • 83
  • 121
0

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

Mark Brackett
  • 84,552
  • 17
  • 108
  • 152