Created
December 16, 2011 15:06
-
-
Save goenning/1486389 to your computer and use it in GitHub Desktop.
Resource file to javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet] | |
public ActionResult LocalizedScript() | |
{ | |
string javaScript = SerializeResourceToJavaScript(); | |
return Content(javaScript, "application/javascript"); | |
} | |
[NonAction] | |
private string SerializeResourceToJavaScript() | |
{ | |
CultureInfo uiCulture = Thread.CurrentThread.CurrentUICulture; | |
var resourceSet = CommonStrings.ResourceManager.GetResourceSet(uiCulture, true, true); | |
StringBuilder js = new StringBuilder(); | |
js.Append("var CommonStrings = {").Append(Environment.NewLine); | |
foreach (DictionaryEntry entry in resourceSet) | |
{ | |
js.AppendFormat("\"{0}\": \"{1}\",", entry.Key.ToString(), entry.Value.ToString()); | |
js.AppendLine(); | |
} | |
js.Append("}"); | |
return js.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment