What is the URL for "THIS" page?

I would like to be able to provide an ability where each of the pages in a web site can be viewed in several different languages.  Go Network has  such a capability (http://translator.go.com/ssi/webkit.html) but  it requires that each page's complete URL be included in the  HTML code.

I need a way such that the same code can be included on each  page, and that somehow it can call forth its own URL.

I posed this question over in HTML, but was told there that it could not be done except using a server based scripting system like PHP, but that it shoulc be possible with Javascript. If I need to involve the server I would like to limit that involvement to just simple CGI, and preferably not even that.

Is there a way to do this with just plain HTML? Is there a way a CGI Script could fill in the URL, or perhaps something with Server Side Includes, or a combination of CGI and SSI? If none  of those are possible, can it be done with Javascript, and if so  how?

I can automatically add a block of code to every page on my site usine UltraEdit, but is there any sort of INCLUDE statement  in HTML (without using something like FrontPage) that would do the job?
LVL 11
singletonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

clockwatcherCommented:
I'm not exactly clear on what you're trying to do-- location.href will give you the current URL of the page.

<html>
<body>
<form>
<input type="button" onclick="alert(location.href);" value="Click Me">
</form>
</body>
</html>

0
singletonAuthor Commented:
http://www.tcs.org/translatetest.htm has an example of what I am trying to do.  The particular web page is insignificant, it is jjust what I was working on when your message came in.

At the top there are three items.

On the left your example works

On the right, if I hard code the URL, i.e.
<input type="hidden" name="url" value="http://www.tcs.org/webpage0.htm" > it works

But in the center I tried your approach, i.e.
type="hidden" name="url" value="alert(location.href);" >

and it does not work, but instead says:
Sorry, we could not translate this page. It is likely that the URL is incorrect. Please re-enter the URL and try again.  
0
clockwatcherCommented:
alert simply displays an alert box.  If you want to include the value of the hidden field "url".  

Replace this

<input type="hidden" name="url" value="alert(location.href);" >

with this:

<script language="javascript"><!--
document.write('<input type="hidden" name="url" value="' + location.href + '">');
// -->
</script>
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

singletonAuthor Commented:
I think I did what you asked:

<td><FORM NAME="systran" ACTION="http://translator.go.com/" METHOD=POST>
<input type="hidden" name="input_type" value="url">
<input <script language="javascript"><!--
    document.write('<input type="hidden" name="url" value="' +
    location.href + '">');
    // -->
    </script>
<font face=geneva,arial size=2><b>Translate this page</b></font>
<SELECT NAME="lp" >
    <OPTION VALUE="en_sp" selected> to Spanish
    <OPTION VALUE="en_fr"> to French
    <OPTION VALUE="en_ge"> to German
    <OPTION VALUE="en_it"> to Italian
    <OPTION VALUE="en_pt"> to Portuguese
</SELECT><br><INPUT TYPE="submit" VALUE="Translate"><br>
<font face=geneva,arial size=1>powered by</font><font
face=geneva,arial size=2>&nbsp;<a
href="http://www.systransoft.com/english/products/personal/go_personal.html">SYSTRAN
Translation Software</a></font></form></td>

and the center example (first of two translate boxes) at http://www.tcs.org/translatetest.htm just shows up as if no URL had been sent.
0
clockwatcherCommented:
If the above represents a copy and paste of what you've currently got, then you've got a mistake.  You didn't remove all of the <input> tag, you've got some funky "<input" half open tag.

Basically what the script is doing is writing out the entire input tag for you.

Change this:

<input <script language="javascript"><!--
    document.write('<input type="hidden" name="url" value="' +
    location.href + '">');
    // -->
    </script>

To just this:

<script language="javascript"><!--

document.write('<input type="hidden" name="url" value="' + location.href + '">');

// -->
</script>
0
Michel PlungjanIT ExpertCommented:
No need to document.write:

<FORM NAME="systran" ACTION="http://translator.go.com/" METHOD=POST onSubmit="this.url.value=window.location.href">

<input type="hidden" name="input_type" value="url">
<input type="hidden" name="url" value="">
<font face=geneva,arial size=2><b>Translate this page</b></font>
<SELECT NAME="lp" > 
<OPTION VALUE="en_sp" selected> to Spanish
<OPTION VALUE="en_fr"> to French
<OPTION VALUE="en_ge"> to German
<OPTION VALUE="en_it"> to Italian
<OPTION VALUE="en_pt"> to Portuguese
</SELECT><br>
<INPUT TYPE="submit" VALUE="Translate"><br>
<font face=geneva,arial size=1>powered by</font><font  face=geneva,arial size=2>&nbsp;<a  href="http://www.systransoft.com/english/products/personal/go_personal.html">SYSTRAN Translation Software</a></font></form></td>

Michel
0
singletonAuthor Commented:
Fantastic.  Both clockwatcher and mplungjan have provided solutions which work (check http://www.tcs.org/translatetest.htm)

clockwatcher is ONE and mplungjan is TWO

I don't know enough about Javascript to know which is more deserving of the points, and also I don't think I can award them to a comment. What should I do? Ask one to "answer" the question and award the points, or delete the question and pose two 100 point questions and let each answer one, or what?

Also there is a lot of code involved here. Is there any way to implement any sort of "include" statement without using an overbearing program like Front Page? I like to edit my web pages with UltraEdit (sort of a super version of Notepad).
0
singletonAuthor Commented:
Just thought you might get a chuckle out of this.  It happens with both clockwatcher and mplungjan solutions.

On http://www.tcs.org/translatetest.htm select either box, and translate to some language. You will see the box there, in that language. Then select it to translate it again.  You get a translate page in the second language.  It is not hard to see why - the URL of the first translate is http://translator.go.com/ even though it displays with my page translated. I don't see a way around it, and am not seriously worried about it, just thought it was interesting.
0
Michel PlungjanIT ExpertCommented:
Both solutions are identical in effect - I believe my version is the most elegant and the least intrusive, I do not say that to get the points though.

You can ask Customer Services to help split the points and still save teh question as a PAQ...

To fix the double translation, try this:

<FORM NAME="systran" ACTION="http://translator.go.com/" METHOD=POST
onSubmit="
if (window.location.href.toLowerCase().indexOf('translator') !=-1) {
   ref = document.referrer;
   if (ref = '') ref = prompt('Sorry - I lost the page, please give me the url again','');
   if (ref != '') this.url.value=ref;
   else {
      alert('I apologise, but I am now totally confused');
      return false;
   }
}
else {
   this.url.value=window.location.href;
   return true;
}
"> 
0
Michel PlungjanIT ExpertCommented:
The complete form can be included if you use SSI (Server Side Include)
otherwise the complete form can be written with javascript and included in a js file...

BTW: Here is a shorter version of the above witout error handling:
<FORM NAME="systran" ACTION="http://translator.go.com/" METHOD=POST
onSubmit="
if (window.location.href.toLowerCase().indexOf('translator') !=-1)
   this.url.value=document.referrer;
else this.url.value=window.location.href;">
..
..
..
..
</form>
0
singletonAuthor Commented:
Don't know what happened to my previous attempt to send this comment, but will try again.

< The complete form can be included if you use SSI (Server Side Include)  otherwise the complete form can be written with javascript and included in a js file...

Can you explain the differences between the two?  I use SSI on some files (<!--#echo var="LAST_MODIFIED"-->) but avoid it on most, because the file must be shtm or shtml, rather than htm/html, and if I do a file open to open the file on my hard disk (in netscape) it only looks for htm/html and I have to change to all files to find the shtm/shtml.

Does SSI offer enough advantages over the js solution to justify it, or is the js solution better?

Can you show examples of both alternatives, in the form of an "answer" and I can award you the points, and perhaps clockwatcher can let me know some related question he could answer and I could post another 100 point one for him to answer.
0
kmartin7Commented:
????

I posted a possible solution to this yesterday.  I get email saying that so-and-so has added a comment, but my post is not here!!!

Y2K??

Kurt
0
singletonAuthor Commented:
It beats me. I have not (and don't think I could) deleted any comment or solution. AFAIK, even if I rejected a solution, it would still be shown.

Was your solution better than the one from mplungjan?
0
kmartin7Commented:
After re-reading your original post, it probably is not better than Michel's. I thought that you wanted to redirect the user to their own native language. I tried this using document.referrer and window.location.href.toLowerCase().indexOf('...') to detect which country of origin using (whether it was .uk or .jp or .com) and redirecting to the appropriate part of the site.  This method is by no means fool-proof, but I thought at the time it was a start.

Kurt
0
singletonAuthor Commented:
Wow. That would really be something interesting, but would be hard as hell to test out, and as you indicated would not be foolproof.
0
Michel PlungjanIT ExpertCommented:
Kurt, that would only work if singleton had a site for each language - I think you confuse it with the reverse lookup of the ip address which is server side only...

Singleton: The js file is the simplest but is not supported by IE3.0. If you can live with that, put this in a fiel and call it for example translate.js - watch the quotes and each tText += is a new line:

// JS File to be included
var tText = "<TABLE><TR><td>";
tText += '<FORM NAME="systran"';
tText += ' ACTION="http://translator.go.com/"';
tText += ' METHOD=POST';
tText += ' onSubmit="';
tText += 'if (window.location.href.toLowerCase().indexOf(\'translator\') !=-1) ';
tText += '   this.url.value=document.referrer;';
tText += 'else this.url.value=window.location.href;">';
tText += '<input type="hidden" name="input_type" value="url">';
tText += '<input type="hidden" name="url" value="">'
tText += '<font face=geneva,arial size=2><b>Translate this page</b></font>';
tText += '<SELECT NAME="lp" >';
tText += '<OPTION VALUE="en_sp" selected> to Spanish';
tText += '<OPTION VALUE="en_fr"> to French';
tText += '<OPTION VALUE="en_ge"> to German';
tText += '<OPTION VALUE="en_it"> to Italian';
tText += '<OPTION VALUE="en_pt"> to Portuguese';
tText += '</SELECT><br>';
<INPUT TYPE="submit" VALUE="Translate"><br>';
tText += '&nbsp;<a  href="http://www.systransoft.com/english/products/personal/go_personal.html">SYSTRAN Translation Software</a></font>';
tText += '</form></td></TR></TABLE>';
document.write(tText);

and in your pages have

<script language="javascript" src="translate.js"></script>

Any error is due ot paste or missing quotes..

Michel


Michel
0
singletonAuthor Commented:
I will certainly give it a try. If you want to post something as an "answer" so that I can award the points we can close this one out.

I just made a fantastic discovery.  The original attempt, which did not use jscript, is at http://www.apcug.org/translate2.shtm and not only will it translate that page, all links will be translated also, so I don't absolutely have to have a jscript solution (which would not work on older browsers).

But I am thrilled at the possibilities of Jscript, and am going to try to find the time to learn more about it.
0
Michel PlungjanIT ExpertCommented:
something

Michel
PS: but clockwatcher aught to have some points too

Michel
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
singletonAuthor Commented:
I don't disagree. I will post another question and specifically ask clockwatcher to answer it.
0
kmartin7Commented:
Michel - you are right.  When I originally read the question, I thought my method was what singleton wanted.  But, upon re-reading the question, I soon realized it wasn't what was needed.

It really doesn't matter now anyway =)

Happy New Year,
(The new Millenium doesn't start until 1-1-2001)

Kurt
0
Michel PlungjanIT ExpertCommented:
I missed a tText += ' in front of
<INPUT TYPE="submit" VALUE="Translate"><br>';

and this is one line
tText += '&nbsp;<a  href="http://www.systransoft.com/english/products/personal/go_personal.html">SYSTRAN Translation Software</a></font>';
0
Michel PlungjanIT ExpertCommented:
same to you

Michel
0
singletonAuthor Commented:
Thank you.  I had just tried it and it did not work.  However once translated it appears the translated one does not have the text, presumably because their computer does not have the translate.js file.

Example 3 on http://www.tcs.org/translatetest.htm
0
Michel PlungjanIT ExpertCommented:
You mean it works and then the entry is missing on their site?

easily fixed:

change the script tags in the document:

<script language="javascript" src="http://www.tcs.org/translate.js"></script>

or if you do not want the table at all at their site:

if (window.location.href.toLowerCase().indexOf(\'translator\') ==-1)
document.write('<SCR'+'IPT LANGUAGE="JavaScript" SRC="translate.js"></SCR'+'IPT>');

and put the complete table inside the tText


Michel
0
singletonAuthor Commented:
Have not tried the second alternative yet, but the first did not work:

http://www.tcs.org/translatetest.htm    box number three
0
Michel PlungjanIT ExpertCommented:
é las cosas se parecen tan lentas esta noche?

                                                Ficheros que se utilizarán en
                                                       De enero el 15
                                     Reunión De Grupo De Interés Especial Del Internet

     Tracert

Works for me in netscape 4.7

Michel
0
Michel PlungjanIT ExpertCommented:
And IE5:

Por qué las cosas se parecen tan lentas esta noche?
Ficheros que se utilizarán en
De enero el 15
0
singletonAuthor Commented:
The translation works fine, but is there anything in the "tres" box on the translated page, like there is on the uno and dos boxes?
0
Michel PlungjanIT ExpertCommented:
It should work
HOWEVER if one looks in the translated file it says

<!--  JAVASCRIPT REMOVED  -->      

so there you are...

Put the complete table in the javascript and it will not look silly.

Michel


0
singletonAuthor Commented:
Yes I noticed that after I posted the message.  Don't know why they would suppress importing the js file, but allow the same code to be processed if it came on the page to be translated, but such is life.  You are correct.  Number two ("dos") is with the complete table in the javascript.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.