Home > Uncategorized > Resource files for Classic ASP

Resource files for Classic ASP

I was looking to localize a classic ASP website, and was considering upgrading it to ASP.NET, but it seemed way too much work, so I decided to look to see if it was possible to create a localization framework for classic ASP. using the same type of resx files that are used for asp.net
 
So, given a simple piece of xml in semi-typical resx format:
 
<root>
 <data name="Hello!">
  Ciao!
 </data>
</root>
 
I then wrote an include file in classic asp, to handle translations in the form
 
<%=Translate("Hello!")%>
 
(Precursed by a initResources("strings-it.xml"))
 
 
 Dim xmlResx
 Function initResources(ResourceFile)
  Set xmlResx=Server.CreateObject("Microsoft.XMLDOM")
  xmlResx.async=false
  xmlResx.load(Server.MapPath(ResourceFile))
 End Function
 
 Function Translate(english)
  Set objLst = xmlResx.getElementsByTagName("data")
  For i = 0 to (objLst.length -1)
    EnglishText = objLst.item(i).attributes.getNamedItem("name").text
 If english=EnglishText Then
  Translate= objLst.item(i).text
  Exit For
 End If
  Next
 End Function
 
20 Lines of code, prevented an overhaul of my application to .NET.
 
Ultimately, I plan this to be used for a spanish version of www.openmerchantaccount.com
 
 
 
 
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment