tags:

views:

49

answers:

5

Hi, I am working on adding a mulit-language feature to an asp classic site. I was trying to do this by using if else statements to select the include I want to load. After a bit of research I found out that includes files are loaded up before any code is handled.

How can I get around this issue and load up the proper include files? Is there a better way of doing this?

Thanks!

+1  A: 

You can't, as you've discovered, dynamically choose includes. Includes are handled statically before any script is executed.

The next best thing is Server.Execute. You can use logic to choose what additional files to execute, however whether this fits with your solution is another matter. What do your includes currently contain?

Another approach would be place your "multi-language" choices in some data format such a set of CSV files or XML files. Your code would then load the appropriate "language file".

AnthonyWJones
I tried the server.execute method with my language files, but it didn't work. My language files just contained constants with the label and the label value. I was going for a simple templating system, but I'm having trouble overcoming all these limitations in asp.
chobo
@chobo: Ok so you have set of constants, what languages do you support? Are they all within the western latin character set? If not you may have another serious issue to contend with.
AnthonyWJones
You could use the session object to store data between calls to `server.execute` ..
Gaby
The system makes heavy use of frames, and session variables get lost in frames.
chobo
A: 

It can be done - just use include virtual instead of file

edit

I stand corrected - obviously i tried too hard to forget those dark ages.

Years ago i worked on a project where we would create a "container page" for every language version an then include the respective portion of constants.

A working spinoff is still running and if you check the page source of this site you can get an idea how we plugged the pages together. Some of the included scripts identified by their SVN id tags even included more scripts and maintaining this slowly turned into a nightmare.

I'm sorry i was wrong about the conditional include and there should be a better solution than the one mentioned above.

Filburt
I'm trying to include actual asp files that contain constants. I tried your solution and it errors and tells me I need to Redimm everything, so it is still trying to load up all my includes not just the ones I want it to.
chobo
@chobo sorry to put you on the wrong path - Anthony is right.
Filburt
A: 

I'm not sure if this idea helps, but you could dim the language string variables in one ASP file and then set the variables in separate ASP functions. Then your if statements can call the proper function to set the ASP language string variables. You would not be breaking out the language string into separate files, but it might accomplish what you are trying to achieve.

For example:

dim str1, str2

sub SetLangX
   str1 = "String val 1 for lang X"
   str2 = "String val 2 for lang X"
end sub

sub SetLangY
   str1 = "String val 1 for lang Y"
   str2 = "String val 2 for lang Y"
end sub
Nathan
+1  A: 

After countless hours I think I finally came up with a solution. I create xml files for each language (en.xml, fr.xml) with a super simple structure (just a label element with an id and value).

By using an attribute that has a similar name to the label I want to replace I can figure out where everything needs to go, and just pull the value.

chobo
+1 Adding a Xml ResourceManager to classic asp is a cool solution.
Filburt
A: 

4guysfromrolla has a pretty good article on this. Link below ...

http://www.4guysfromrolla.com/ASPScripts/PrintPage.asp?REF=/webtech/022504-1.shtml

Fred Clown