Ok, I created a generic web service to allow me to grab resources and return them in a dictionary (perhaps the best way to convert to a dictionary) ...
<WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False, XmlSerializeString:=True)> _ Public Function GetResources(ByVal resourceFileName As String, ByVal culture As String) As Dictionary(Of String, String) Dim reader As New System.Resources.ResXResourceReader(String.Format(Server.MapPath("/App_GlobalResources/{0}.{1}.resx"), resourceFileName, culture)) If reader IsNot Nothing Then Dim d As New Dictionary(Of String, String) Dim enumerator As System.Collections.IDictionaryEnumerator = reader.GetEnumerator() While enumerator.MoveNext d.Add(enumerator.Key, enumerator.Value) End While Return d End If Return Nothing End Function
Then I can get this json result and assign it to a local variable:
// load resources $.ajax({ type: "POST", url: "mapping.asmx/GetResources", contentType: "application/json; charset=utf-8", dataType: "json", data: '{"resourceFileName":"common","culture":"en-CA"}', cache: true, async: false, success: function(data) { localizations = data.d; } });
Then you can grab your value from a local variable as follows:
localizations.Key1
The only catch here is that if you want to assign localizations to a global variable, you must run it async = false, otherwise you will not have translations available when you need them. I am trying to use "get", so I can cache the answer, but it does not work for me. See this question:
Unable to return dictionary (Of String, String) via GET ajax web request, works with POST