title: A localized scriptbundle solution
body: <p>Hi I am currently using the asp.net MVC 4 rc with System.Web.Optimization. Since my site needs to be localized according to the user preference I am working with the jquery.globalize plugin.</p>
  
  <p>I would very much want to subclass the ScriptBundle class and determine what files to bundle according to the <code>System.Threading.Thread.CurrentThread.CurrentUICulture</code>. That would look like this:</p>
  
  <pre><code>bundles.Add(new LocalizedScriptBundle("~/bundles/jqueryglobal")
                               .Include("~/Scripts/jquery.globalize/globalize.js")
                               .Include("~/Scripts/jquery.globalize/cultures/globalize.culture.{0}.js", 
                                         () =&gt; new object[] { Thread.CurrentThread.CurrentUICulture })
                      ));
  </code></pre>
  
  <p>For example if the ui culture is "en-GB" I would like the following files to be picked up (minified of course and if possible cached aswell until a script file or the currentui culture changes).</p>
  
  <ul>
  <li>"~/Scripts/jquery.globalize/globalize.js"</li>
  <li>"~/Scripts/jquery.globalize/globalize-en-GB.js" &lt;-- if this file does not exist on the sever file system so fallback to globalize-en.js.</li>
  </ul>
  
  <p>I tried overloading the Include method with something like the following but this wont work because it is not evaluated on request but on startup of the application.</p>
  
  <pre><code>public class LocalizedScriptBundle : ScriptBundle
  {
      public LocalizedScriptBundle(string virtualPath)
          : base(virtualPath) { 
      }
  
      public Bundle Include(string virtualPathMask, Func&lt;object[]&gt; getargs) {
          string virtualPath = string.Format(virtualPathMask, getargs());
          this.Include(virtualPath);
          return this;
      }
  
  }
  </code></pre>
  
  <p>Thanks </p>
  
  <p>Constantinos</p>