Print Page | Close Window

Dynamic Includes

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=12146
Printed Date: 31 March 2026 at 1:17am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Dynamic Includes
Posted By: theSCIENTIST
Subject: Dynamic Includes
Date Posted: 12 October 2004 at 5:06pm
What I need is to make a language changer for a project I'm working on, all language files have the following directory structure:

+languages
| en
|- files
| pt
|- files
and so on...

ASP pages will then call the correct file according to the value on the cookie (en/pt...), but I'm using SSI to include the language file and it does not allow dynamic values.

Now, for what I could gather SSI does not allow dynamic includes, you know the (<!-- #include file="page<%= rnd %>.asp" -->) this would be great, but because SSI's are included before the ASP parser, the <%= value %> would not be known, and it doen't work.

Then I tried the Server.Execute, also failed because it loads the file, processes it and unloads it, so it will no longer be available to pass language constants along.

I've been banging my head on the wall with this one, still no solution, has anyone done something similar, or know how can I do this? Remember I would like to use the directory stucture as above.

Thanks.

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com



Replies:
Posted By: Mart
Date Posted: 12 October 2004 at 5:37pm
You could do it another way, just have 1 static include file "languagefunctions.asp" and include a function like GetLanguage(Key) the GetLanguage function will open the appropriate file (or query the db) for the language and will return a value based on the key that was passed through.


Posted By: theSCIENTIST
Date Posted: 12 October 2004 at 7:05pm
Hi, I was actually exploring that possibility, since I have done exactly that for the skin changer, however, the language files are several files, each page requests the lang file it needs, (ie. gallery script requests only the gallery lang file, not a big global lang file) how do I go about doing that?

Each file has an Include on top that includes the language file it needs, and my other setup is like this: I have a language changer form that submits it's selection to a language processor page, this page then sets the cookie, and after that I'm kinda stuck.

I guess I could do a (Select Case) like this on the requesting page:

<%

Select Case Request.Cookies("Kahombo")("Language")
Case "en"
%>
<!--#include file="path/en.asp"--%>
<% Case "pt" %>
<!--#include file="path/pt.asp"--%>
<% End Select %>


The problem with this approach is that all files are included regardless, but only one is processed, also as the languages list gets bigger, it will get slower as all files must be included.

There must be another way.

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com


Posted By: dpyers
Date Posted: 13 October 2004 at 12:11am

Don't know the logic flow involved here, particularly avter the language files execute, but depending upon how the flow is structured, you might want to look at doing Server.Transfer.

Doesn't open up a new memory space like Server.Execute and as a result - IIRC - any stuff in a request/response onbject available to the original script is available to the transferred script. But you don't return to the original script. You'd have to have the subsequent statements from the original script incorporated within an include in each transferred script.



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: theSCIENTIST
Date Posted: 13 October 2004 at 8:52am
What I'm trying to do is say for example you want to add multi-language capabilities to this forums, you'll have a drop-down list with the languages, users will then select a lang, and submit the form.

How would you do it after that?

dpyers: Did you mean using Server.Transfer with the PreserveForm option? How so? How do you plan to dynamically include the correct lang file? Thx.

All forum files contain variables that are the same in all language files, the difference is the value of those variables.

I've been looking around for this, and it seams to be a real pain in the back side to do in ASP, I've read a large discussion last night about it, it took me till 5am and the final word was that there's no easy way without some kind of compromise.

I may also look into do it in ASP.NET and combite it with ASP somehow, Mart, michael or any other .NET wiz, please comment.

Lots of people out there have this issue, I plan to crack it, with your help off-course ;) I will not do anything else until this is resolved as it is really important for my project, this morning I was even dreaming about language files :) damn this is getting bad. Thx.

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com


Posted By: Mart
Date Posted: 13 October 2004 at 11:26am
I can help  you do it in .NET and access it through ASP if you have physical access to the server register a .NET component in the GAC


Posted By: theSCIENTIST
Date Posted: 13 October 2004 at 11:43am
COM? I rather not use COM as the project will later be hosted on many different hosts and some will not have this ability, so I would like to stay away from COM.

Anyway, if you can tell me the process involved.

Is there any other way to do this in ASP? Also, with no COM how to in ASP.NET?

Thx.

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com


Posted By: Mart
Date Posted: 13 October 2004 at 12:12pm
No not COM, the only way you could do it with .NET is to make a new component and register it in the server GAC, you can then access it LIKE a Com component but it is really a .net component. All you basically have to be able to do is be able to run a batch file


Posted By: theSCIENTIST
Date Posted: 13 October 2004 at 12:28pm
GACing may not be possible, because once I release the application, most users will not have access to enable this, I can do it, but I have physical access to the server, most clients don't.

I'm inclined at this point to make the hard decision to use a database for the language changer feature, god damn it, why can't I use a standart ASP file full of Consts and one language file per language supported?

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com


Posted By: theSCIENTIST
Date Posted: 13 October 2004 at 3:39pm
Humm, I'm now down to this options, and I should start on a solution tommorrow:

1. Use a database :: I don't like this too much for this task.

2. Use application variables :: Again, not one of my prefered options.

3. Use the dictionary object :: Still haven't persued this too much, I think it uses the Index service if I'm not mistaken and haven't read enough about this to determind it's pros and cons to use it as a site wide language storage.

4. Use XML files :: So far this is the best option, however there's still a few things I don't know, show I use XMLDOM or XMLHTTP object? Which one is best for this task? Are this objects available in the majority of hosts?

Thx.

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com


Posted By: Mart
Date Posted: 13 October 2004 at 3:48pm
99.9% of hosts will have XMLDOM, some (crap) hosts may disable XMLHTTP...
XMLHTTP is used for downloading documents from other websites so I imagine this will not help you much in langauge files, I thiunk XMLDOM is what you want if you want to parse Xml documents, as I say, you should have no problem using XMLDOM on most hosts.


Posted By: theSCIENTIST
Date Posted: 14 October 2004 at 3:01am
Great, I'm already busy XMLing full steam ahead, and so far so good, there's still some concurrency issues, well, maybe not issues, just concerns at this point.

1. How does XML fare when there's several users accessing it simultaneousy?

2. Or, shouldn't I lock the file while reading with (xmlDoc.Async = False)?

3. Are there other issues I should be aware off?

Last thing I want is to go with all this work ahead of converting my project to XML site wide language files and then there's problems when app goes live and it can't be used.

Thanks guys.

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net