1 public static JavaScriptResult JavascriptResources(ResourceManager manager, string resourceObjectName, CultureInfo culture)
2 {
3 ResourceSet resourceSet = manager.GetResourceSet(culture, true, true);
4
5 StringBuilder sb = new StringBuilder();
6
7 sb.AppendFormat("var {0}=new Object();", resourceObjectName);
8
9 var enumerator = resourceSet.GetEnumerator();
10 while (enumerator.MoveNext())
11 {
12 sb.AppendFormat("{0}.{1}='{2}';", resourceObjectName, enumerator.Key,
13 System.Web.HttpUtility.JavaScriptStringEncode(enumerator.Value.ToString()));
14 }
15
16 return new JavaScriptResult()
17 {
18 Script = sb.ToString()
19 };
20 }
21
1public class ResourcesController : Controller
2{
3 [OutputCache(Duration = 36000, VaryByParam = "lang")]
4 // Duration can be many hours as embedded resources cannot change without recompiling.
5 // For the clients, I think 10 hours is good.
6 public JavaScriptResult Index(string lang)
7 {
8 var culture = new CultureInfo(lang);
9 return Helpers.JavascriptResources(Resources.Client.ResourceManager,
10 "Client", culture);
11 }
12}
13