title: Localizing JavaScript strings in an ASP.NET Web Forms application
body: <p>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. </p>
  
  <p>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.</p>
  
  <p>We're currently using two different approaches to handle this scenario, but I'm not completely satisfied with either. </p>
  
  <ol>
  <li><p>Write the bulk of the code in a jQuery plugin style, then place a <code>script</code> block on the <code>.aspx</code> page where we'll pull in values from a <code>.resx</code> file and feed them into the plugin code. Here's an example in pseudo code: </p>
  
  <pre><code> &lt;script&gt;
      var view;
      $(function() {
          view = {
              columnHeaders: { 
                  productNumber = &lt;%$ Resources:WidgetProductNumber_HeaderText %&gt;, 
                  productDescription = &lt;%$ Resources:WidgetProductDescription_HeaderText %&gt; 
              }
          };
  
      });
  &lt;/script&gt;
  </code></pre></li>
  <li><p>Place the JavaScript in plain <code>.js</code> files with custom tokens in place of strings. We have a handrolled <code>HttpModule</code> that will parse JavaScript files and replace the tokens with values from any existing <code>.resx</code> file whose file name matches the name of the JavaScript file being processed.</p></li>
  </ol>
  
  <p>Both approaches have problems. I'd prefer to keep our JavaScript code separate from our <code>.aspx</code> pages to make it more unobtrusive and reusable. </p>
  
  <p>The <code>HttpModule</code> 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 <code>HttpModule</code>, 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. </p>
  
  <p>Are there any other tried-and-true strategies for approaching this problem in ASP.NET?</p>