Skip to content

Instantly share code, notes, and snippets.

@devfred
Forked from SCullman/view.ascx
Created October 22, 2015 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devfred/41d9f86b1d854c408224 to your computer and use it in GitHub Desktop.
Save devfred/41d9f86b1d854c408224 to your computer and use it in GitHub Desktop.
DNN, ko and localization
<script>
var resources = <%=Resources%>;
var viewModel = {localize:resources};
ko.applyBindings(viewModel);
</script>
<span data-bind="text:localize.Message"></span>
<span data-bind="text:localize.Message_Help"></span>
....
protected string Resources
{
get
{
using (var rsxr = new ResXResourceReader(MapPath(LocalResourceFile + ".ascx.resx")))
{
var res = rsxr.OfType<DictionaryEntry>()
.ToDictionary(
entry => entry.Key.ToString().Replace(".Text", "").Replace(".", "_"),
entry => DotNetNuke.UI.Utilities.ClientAPI.GetSafeJSString(
LocalizeString(entry.Key.ToString())));
return JsonConvert.SerializeObject(res);
};
}
}
...
<root>
<data name="Message.Help" xml:space="preserve">
<value>Help us to save the world</value>
</data>
<data name="Message.Text" xml:space="preserve">
<value>Hello World</value>
</data>
</root>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment