Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Multiple Language Class

Status
Not open for further replies.

cfsponge

Programmer
Feb 22, 2006
44
US
I need to develop a multi language feature for a website and am trying to think of the best way possible to store two more languages for context and instructions. I am thinking of generating a class with a function per language, and then create an array to hold all the instructions, one per element.
The only drawback to this is the lack of structure arrays in ASP.

Does anyone else have another idea? A session var would be too heavy on the server with the size it would be I think.
 
Just use a simple array of words. Here is a simplistic version of what I mean. This is in VBScript but you can easily adapt it for ASP.
Code:
dim lang
const langEng = 0, langGer = 1, langItal = 2, langMax = 3
function LangWord (theWord, theLang)
   dim result
   result = lang(theLang) & theWord
   for i = 0 to ubound(lang) step langMax
      if theWord = lang(i) then
	 result = lang(i + theLang)
         exit for
      end if
   next
   LangWord = result
end function

lang = Array (_
   "English", "German", "Italian", _
   "one", "ein", "uno",_
   "two", "zwei", "duos")


WScript.echo LangWord ("one", langEng)
WScript.echo LangWord ("two", langGer)
WScript.echo LangWord ("English", langItal)
It would be more efficient if you used numeric indices but if you aren't too worried about efficiency or have a team of non-cooperative programmers who keep on stepping on each other's toes, then the above will suffice.
 
Thank you for this excellent function. I'll adjust it for ASP and let you know how it works.
 
It works well so far. My only question to you is whether the efficiency you speak of is in terms of process speed or content management of the text?
 
It is not very efficient in terms of process speed since it trawls through the whole array looking for the word. The alternatives are

1) use a dictionary - it is a long time since I've used this type of collection
2) Use numerics instead of strings - the comparison is faster
3) Use numeric indices to take you straight to the word in a 2D array. No need to look up anything then but you have to make sure the indices are correct. The problem here is that you have to define a whole load of constants and deleting one word could easily upset the system.
 
The Dictionary object works perfectly. Thank GOD ASP some primitive associative array skills. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top