With 20/20 DataShed, the webmaster or administrator can define a "default" language (the thisAppDefaultLanguage option) but the web site can also be displayed in multiple-languages simultaneously if the languages.xml file contains multiple languages nodes.
This article demonstrates how to build a plug-in that you can incorporate into your own web site to provide your visitors the ability to view your web site in any language of their choice.
In this tutorial, we will perform the following actions:
<%@ Language="VBScript" ENABLESESSIONSTATE="False" %>
<%
Option Explicit
response.buffer = true
dim booleanIsParentFolder
booleanIsParentFolder = True
%>
<!--#include file="_globals.asp"-->
<%
CONST booleanWriteImages = False
dim dictLanguages
set dictLanguages = getLanguages
IF dictLanguages.Count > 1 THEN
%>
<ul class="chooseLanguagesUL">
<%
dim strLanguageID
FOR EACH strLanguageID IN dictLanguages
%>
<li id="<%=StripNonWordCharacters(strLanguageID)%>LI">
<a href="<%=CreatePostBackLink(False,"listings.asp?","strLanguage>"& strLanguageID)%>">
<% IF booleanWriteImages THEN %>
<img src="<%=MapFullURL("images/"& strLanguageID &".gif")%>" />
<% END IF %>
<span><%=dictLanguages(strLanguageID)%></span>
</a>
</li>
<% NEXT %>
</ul>
<%
END IF
set dictLanguages = nothing
FUNCTION getLanguages
dim dictTemp
set dictTemp = Server.CreateObject("Scripting.Dictionary")
dim objXML
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.load(MapPhysicalPath("xml_rss/languages.xml"))
IF objXML.parseError.errorCode <> 0 THEN
response.write("Error: "& objXML.parseError.errorCode &"<br />")
response.write("Line: "& objXML.parseError.line &"<br />")
response.write("Reason: "& objXML.parseError.reason)
END IF
dim listCultures
set listCultures = objXML.documentElement.selectNodes("language/culture")
dim objCultureNode
FOR EACH objCultureNode IN listCultures
dictTemp.Add objCultureNode.text,objCultureNode.parentNode.selectSingleNode("friendlyName").text
NEXT
set getLanguages = dictTemp
set dictTemp = nothing
END FUNCTION
%>
In the next section, we'll examine this code thoroughly.
Example: http://www.YOUR_WEB_SITE.com/folder-names/_Free2020ChooseLanguage.aspYou should see a list of hyperlinks which display the language names available in 20/20 DataShed on your web site. If you see an error message, then please restart this tutorial and pay close attention to the instructions.
ul.chooseLanguagesUL { ...your styles... }
ul.chooseLanguagesUL li { ...your styles... }
<li id="encaLI">
Roughly translated, that means "english canadian List Item"http://www.YOUR_website.com/listings.asp?strLanguage=en-caBut it also reads the current querystring and other page parameters...so it's also capable of remembering which item the visitor is currently viewing and/or which search keywords the visitor is currently searching for. Like this:
http://www.YOU_website.com/listings.asp?strLanguage=en-ca&strKeywords=Fireplace&strCurrentPage=4&strPageSize=1By using the CreatePostBackLink() function, we can reasonably assured that the link will be formed correctly.
en-ca.gifWe recommend that these GIF images could be national flags!
sp-sp.gif
fr-ca.gif
http://www.YOUR_website.com/images/es-ar.gifThis code assumes that you have Argentina's flag (es-ar.gif) in your images folder.
Phew! That's a lot of information.
Take a break...then come back and read about the "getLanguages()" function.
| Culture ID | Friendly Name |
| Dictionary KEY | Key VALUE |
| en-ca | English (Canada) |
| is | Icelandic |
| es-cl | Spanish (Chile) |
In the previous sections we created an ASP file -- a "stand-alone" script which produces a list of hyperlinks that your visitor can use to view your web site in any language of their choice. Now we will show you how 20/20 DataShed's skinning engine can execute ("include") that file within your template.
[2020Execute__Free2020ChooseLanguage.asp]
In the example code below, you can see that we'll include the list of links in the "footer" of the file and we've added some simple CSS to apply some pleasant formatting to the list.
<html>
<head>
<title></title>
<style type="text/css">
ul.chooseLanguagesUL li { list-style-type:circle;display:inline;padding-left:15px; }
</style>
</head>
<body>
<!-- HEADER STUFF -->
<h1>Welcome!</h1>
<!-- END OF HEADER STUFF -->
<!-- BODY (Main Content) STUFF -->
... content...
... content...
... content...
<!-- END OF BODY STUFF -->
<!-- FOOTER STUFF -->
[2020Execute__Free2020ChooseLanguage.asp]
<!-- END OF FOOTER STUFF -->
</body>
</html>
Example: http://www.your_domain.com/listings.asp?objApplication=RemoveAllYou should see a new list of links on your page which allows you to switch languages on the fly.