Skip to content

Instantly share code, notes, and snippets.

@dgershman
Created November 6, 2013 23:49
Show Gist options
  • Select an option

  • Save dgershman/7346371 to your computer and use it in GitHub Desktop.

Select an option

Save dgershman/7346371 to your computer and use it in GitHub Desktop.
ResourceManager rm = new ResourceManager(ConfigurationManager.AppSettings["JSResourcesAssemblyType"].ToString(),
Assembly.LoadFile(ConfigurationManager.AppSettings["JSResourcesAssemblyPath"].ToString()));
if (context.Request.QueryString["CultureCode"] == null) return;
var culture = context.Request.QueryString["CultureCode"].ToString();
ResourceSet rs = rm.GetResourceSet(new CultureInfo(culture), true, true);
var sbInitial = "var rm = {";
var sb = new StringBuilder(sbInitial);
var resEnum = rs.GetEnumerator();
while (resEnum.MoveNext())
{
if (sb.ToString() != sbInitial) sb.Append(",");
sb.Append(""" + resEnum.Key + "":"" +
resEnum.Value.ToString().Replace("rn", "").Replace(""", "\"") + """);
}
sb.Append("}");
sb.ToString();
context.Response.ContentType = "text/javascript";
context.Response.Write(sb.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment