Multi-language ASP application

Results 1 to 2 of 2

Thread: Multi-language ASP application

  1. #1
    Eric Marinko Guest

    Default Multi-language ASP application

    I am looking to offer multiple languages in an ASP application. Can anyone suggest a good way of structuring the application so that I can dynamically offer page content in one of 5 possible languages?<BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Multi-language ASP application

    I think the basic trick is something like this:<BR><BR>&#060;%<BR>English = Array("Hello","how are you?","Please come again.")<BR>Spanish = Array("Allo","como esta usted?","Hasta la vista.")<BR>...<BR><BR>&#039 more elegant than this, but this is right idea:<BR>If Request.Form("language") = "English" Then Lang = English<BR>If Request.Form("language") = "Spanish" Then Lang = English<BR>...<BR><BR>Response.Write Lang(0) & ", " & Request.Form("name") & ", " & Lang(1) & "&LT;BR&#062;" <BR>...<BR>Response.Write Lang(2) & "&LT;BR&#062;"<BR>...<BR>************************* ****<BR><BR>The concept is simple enough: Grab the needed word(s) from the appropriate array for the given language.<BR><BR>But that&#039s tedious and horribly error prone! You have to very carefully keep the two arrays "in sync" with no easy visual clues to help you.<BR><BR>The most "generic" solution I can think of is this one:<BR><BR>Create a database table.<BR><BR>The NAMES of the FIELDS in the table are the English (or your native language) words or phrases or at least enough of each to be mnemonic. The VALUES of the fields are the translations.<BR><BR>Thus:<BR><BR>TABLE: Words<BR>Fields:<BR>&nbsp;&nbsp;&nbsp;&nbsp;Langua ge text<BR>&nbsp;&nbsp;&nbsp;&nbsp;Hello text<BR>&nbsp;&nbsp;&nbsp;&nbsp;HowAreYou text<BR>&nbsp;&nbsp;&nbsp;&nbsp;GoodBye text<BR>...<BR><BR>And then the table *contents* might look like this:<BR><BR>English&nbsp;&nbsp;&#124&nbsp;&nbsp;H ello&nbsp;&nbsp;&#124&nbsp;&nbsp;how are you?&nbsp;&nbsp;&#124&nbsp;&nbsp;Come again soon!<BR>Spanish&nbsp;&nbsp;&#124&nbsp;&nbsp;Allo& nbsp;&nbsp;&#124&nbsp;&nbsp;como esta usted?&nbsp;&nbsp;&#124&nbsp;&nbsp;Hasta la vista!<BR>Russisn&nbsp;&nbsp;&#124&nbsp;&nbsp;Zdra vstvujtye&nbsp;&nbsp;&#124&nbsp;&nbsp;kak pazhivajtye?&nbsp;&nbsp;&#124&nbsp;&nbsp;Do skorovo svidaniya<BR><BR>And now your code looks like this:<BR><BR>&#060;%<BR>Set W = conn.Execute "SELECT * FROM Words WHERE Language=&#039" & Request.Form("Language") & "&#039"<BR>...<BR>Response.Write W("Hello") & ", " & Request.Form("name") & ", " & W("HowAreYou") & "&LT;BR&#062;" <BR>...<BR>Response.Write W("GoodBye") & "&LT;BR&#062;"<BR>...<BR><BR>********************* **<BR><BR>This works, and the DB table is easy to maintain since you can "line up" all translations at the same time. But it&#039s kind of slow to do a query for each page. So maybe what you want to do is do the query on the first page and then "persist" the recordset (see ADODB.RecordSet.Save method) from one page to the next (in a session variable?). On the other hand, if the pages come in rapid succession, the DB page will stay "hot" enough that maybe there won&#039t be a performance hit.<BR><BR>*************<BR><BR>Of course, this simple minded approach doesn&#039t work for languages where the grammatic structure is significantly different than English. For example, what about a language that has different forms of address for male and female? Or different word ordering?<BR><BR>One way around that is to drive things the other way around: You put up the full text of a sentence (in the DB or wherever) and have special tokens in the text that indicate where to drop in dynamic data. Maybe something like this:<BR><BR>EnglishSentence1 = "Hello, #FirstName# #LastName#."<BR>JapaneseSentence1 = "Kon nichi wa #LastName#-san."<BR><BR>And then you select the appropriate sentence/paragraph and do<BR><BR>sentence = Replace( sentence, "#FirstName#", Request.Form("FirstName") )<BR>sentence = Replace( sentence, "#LastName#", Request.Form("LastName") )<BR><BR>and the fact that the Japanese version doesn&#039t use the first name won&#039t matter: The replace will do nothing in that case.<BR><BR>******************<BR><BR>So... no solutions. Just things to think about, yes?<BR><BR><BR>p.s.: The last technique is similar to what MS uses in their "FormatMessage" Win32 function call. They use numbered arguments instead of named ones, so I like my solution better from a readability standpoint. But the concept obviously works.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts