One of the apps I work on is a large ASP.NET 3.5 Web Forms app that is used in the U.S., Central and South Americas, and Europe. We're also starting to do more work with AJAX, and thus we need to settle on a strategy for localizing strings in our JavaScript controls.
For example, we have a control written as a jQuery plugin that formats data into a sortable table. The buttons and table columns need to be localizable.
We're currently using two different approaches to handle this scenario, but I'm not completely satisfied with either.
Write the bulk of the code in a jQuery plugin style, then place a
scriptblock on the.aspxpage where we'll pull in values from a.resxfile and feed them into the plugin code. Here's an example in pseudo code:<script> var view; $(function() { view = { columnHeaders: { productNumber = <%$ Resources:WidgetProductNumber_HeaderText %>, productDescription = <%$ Resources:WidgetProductDescription_HeaderText %> } }; }); </script>Place the JavaScript in plain
.jsfiles with custom tokens in place of strings. We have a handrolledHttpModulethat will parse JavaScript files and replace the tokens with values from any existing.resxfile whose file name matches the name of the JavaScript file being processed.
Both approaches have problems. I'd prefer to keep our JavaScript code separate from our .aspx pages to make it more unobtrusive and reusable.
The HttpModule approach is clever but a little opaque to developers. I'm also looking to implement a JavaScript bundler called Rejuicer, which is also written as an HttpModule, and getting these to work together seems like it would require customizing the open source code. I'd prefer to use the code as it's written so that we can upgrade it as the project progresses.
Are there any other tried-and-true strategies for approaching this problem in ASP.NET?