So after playing with my own code after a while I realized that there was a slight flaw in my thinking. Since every application is slightly different in the way it determines what culture to use, and that each request is technically a different Thread, I need a more generic way to capture that information.
I decided to use a querystring value. Here is my updated code in regards to reading the querystring culture, setting it and fired up the appropriate ResourceManager..
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("\r\n", "").Replace("\"", "\\\"") + "\"");
}
sb.Append("}");
sb.ToString();
context.Response.ContentType = "text/javascript";
context.Response.Write(sb.ToString());
Currently rated 1.6 by 33 people
- Currently 1.575758/5 Stars.
- 1
- 2
- 3
- 4
- 5