Forum Moderators: open

Message Too Old, No Replies

html redirect and getting current file name

to make a multi-language site

         

Herenvardo

10:06 am on Apr 24, 2004 (gmt 0)

10+ Year Member



I've two questions, both related with the same problem.
I'm working in a small site (total 22 files, including imgs) that must work both in english and spanish.
I've separated the files in two folders: spanish/ and english/. This make easier to make ampliations to the site and lets the user to know better where s/he is inside the site.
So, these are the two questions:
1: I want the index.htm file in the root dir to auto refresh to the /english/index.htm file, as more transparent to the user as possible. How can I do it?
2: I've a link in each file that lets the user go to the other language home. I'd like to use some kind of scripting to send the user to the page it was already viewing instead.
For example, the user is at /english/file1.htm and clicks the spanish link, then I want to send her/him to /spanish/file1.htm. I know that I could put a different href in each file to do that, the problem is that I want to keep my menu independent of the file it's in (all files will share the same menu). Is there any way to retrieve the current file name to implement this?
Thanks in advance.
Note: I work with remote hosting and only can work with pure html, client-side scripting and ASP.

Thanks again,
Herenvardö

Staffa

11:46 am on Apr 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



auto refresh to the /english/index.htm

to auto refresh you can insert this html tag in your index.htm

<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=english/index.htm">

adjust the content=0 to any number of seconds ie 1, 2, 3 etc if you want to give your visitors time to read an intro or something first before the redirect.

For the second question, I have implemented a system on my site (url in profile) for the same purpose, the pages however need to be in asp.
If that's what you are looking for, I can explain.

nafmo

11:57 am on Apr 24, 2004 (gmt 0)

10+ Year Member



If possible, I would recommend you to use content negotiation to select the language automatically. That way you wouldn't have to mess with client-side redirects. If you're running Apache, there is a lot of documentation about it.

Debian is running this to serve a multitude of translations, the Debian web site has more info.

encyclo

12:51 pm on Apr 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the switch between the two languages, I asked about that in the PHP forum a few weeks ago: [webmasterworld.com...] - as you've got ASP you will need to adapt the code, but the basic idea is there - you parse the URL and switch "/english/" to "/spanish/" in the string. You need to make sure the filenames are identical in both sections, however.

As for the root-level page, a simple 301 redirect with ASP to the default language would be by far the best solution.

bull

5:40 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



I am currently using a javascript solution to redirect my german visitors to my german pages and any other visitors to the english version. It works fine.

sebbothebutcher

8:33 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



how about a javascript like this one?
(altered version from a script i found in one of these forums)

<script language="javascript" type="text/javascript">
var loc=(location.href);
var getit=new Array();
var getit=loc.split('english/');
var filename=getit;
document.write("<a href='http://yoursite.com/spanish/")
document.write(filename[1])
document.write("'>Spanish Version</a>")
</script>

to change to the english version, use something like this:


<script language="javascript" type="text/javascript">
var loc=(location.href);
var getit=new Array();
var getit=loc.split('spanish/');
var filename=getit;
document.write("<a href='http://yoursite.com/english/")
document.write(filename[1])
document.write("'>English Version</a>")
</script>

by clicking on the link the user will be redirected to a page in the folder of the other language. the file has the same name as the one the link is on. it also works if the file is in a subdirectory!

bull

8:37 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



index.html refresh solution I use in every folder's index.html:

var brwsr=navigator.appName;
if(brwsr=="Netscape" ¦¦ brwsr=="Opera")
var language=navigator.language; else
var language=navigator.browserLanguage;
if(language){language=language.substring(0,2);}
if(language == "de") window.location = "indexdeutsch.html";
else window.location = "indexenglish.html";

filenames not the ones I use

sebbothebutcher

8:49 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



so this depends on the browser language?

bull

6:10 pm on Apr 25, 2004 (gmt 0)

10+ Year Member



yes. I additionally use an appropriate <noscript> section with plain text links for SEs and users w/o JS enabled.

tombola

7:31 pm on Apr 25, 2004 (gmt 0)

10+ Year Member



Why don't you use content negotiation?...

[httpd.apache.org...]

Herenvardo

3:34 pm on Apr 26, 2004 (gmt 0)

10+ Year Member



Thanks, guys!
<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=english/index.htm">

Exactly what I was searching for! I had seen something like that somewhere, but I was not sure how it worked.
Thanks ;)

sebbothebutcher:
Your code fits exactly to my problem! Thanks a lot. I'll have to modify it a littel but hope that will work.

bull:
Thanks, but I want to send EVERYBODY to the english version, and then they will switch to spannish if thew want. Don't ask me the reasons, I only do what my boss asks. Even so, good code. I'll probably use it in my home page if someday I make it multilanguage.

If you're running Apache

But I'm not running apache :( I work on a remote host with MS technologies :(:(:(, and I cannot ask to the host to install apache, php, debian nor anything I would work better on... I've to play with their rules :S

encyclo & tombola:
Your answers are interesting, but i'll go on with sebbothebutcher's code: it fits exactly my needs without complications... exactly wath my boss likes :P

EVERYBODY:
Thanks a lot! :)

Herenvardö

PS: I love these forums: everybody always ready to help someone;).

sebbothebutcher

3:54 pm on Apr 26, 2004 (gmt 0)

10+ Year Member



i'm glad i could help you out! this doesn't happen too often... most of the time i am the one who needs help! ;-)
i wish you luck