Results 1 to 8 of 8
  1. #1
    Newbie G-WebServices's Avatar
    Join Date
    January 13th, 2008
    Posts
    27
    Change Site Language without leaving current site section
    I use flag buttons on my website so visitors can click on their desired language in order to switch. My problem is that People who click on a language flag are always taken to the start page or index file for that specific language.

    I want to create a link that will 1. Grab my current url 2. add or change the language subfolder to the url without modifying the rest of the current url. And I want to do this using only 1 external SSI file so that I can update my whole site's language section from just one file.

    My purpose is to allow site visitors to stay on the same section but in a different language.

    For example. If I'm on a boat specific page and the url is:

    www.example.com/topics/boats/luxury.html

    I want readers to be able to click on the Brazilian flag but be taken to the same link but have the /port/ file added to the url:

    www.example.com/port/topics/boats/luxury.html

    Question. Can I create a JavaScript link or any other type of link which lets me use an SSI file but still allows me to take my visitors to their specific language sections within the same section? Only on a different subfolder but having almost the same URL as the previous language?

    Here's my SSI file:


    Code:
    <!--Change Language Div -->
    <div id="language">
    <a href="http://www.example.com/index.html" title="Espa&ntilde;ol"><img src="images/spanishFlag.gif" alt="Spanish Flag"></a>
    <a href="http://www.example.com/eng/index.html" title="English"><img src="images/english.gif" alt="British Flag" ></a>
    <a href="http://www.example.com/port/index.html" title="Portuguese"><img src="images/portuguese.gif" alt="Brazilian Flag"></a>
    </div>
    <!--End Change Language Div-->

  2. #2
    Member MyDayRegistry's Avatar
    Join Date
    March 11th, 2008
    Location
    San Diego, CA
    Posts
    102
    Unfortunately I donít have an answer to your question, but I am very interested if you know of any open source code that I can point my developers to. I did a preliminary search a while back but donít think I was using the right keywords for the search. Any Advice?

  3. #3
    ABW Ambassador PatrickAllmond's Avatar
    Join Date
    September 20th, 2005
    Location
    OKC
    Posts
    1,219
    This should be just a matter of grabbing the URL, changing it, and sending the user to the new URL. There is a variable in PHP that contains the current URL and script/page name. I'd just use that.

    You cannot use Javascript to directly control anything SSI related. Javascript is for the client, SSI is for the server. Your link - whatever it is - needs to get the information back to the server and let the server decide which SSI to use.
    ---
    This response was masterly crafted via the fingers of Patrick Allmond who believe you should StopDoingNothing starting today.
    ---
    Focus Consulting is where I roll | Follow @patrickallmond on Twitter
    Search Engine Marketing | Search Engine Optimization | Social Media | Online Video

  4. #4
    Newbie G-WebServices's Avatar
    Join Date
    January 13th, 2008
    Posts
    27
    This should be just a matter of grabbing the URL, changing it, and sending the user to the new URL. There is a variable in PHP that contains the current URL and script/page name. I'd just use that.
    Yes. Thank you Patrick, that's exactly the type of code I'm looking for. Can you point me in the right direction?

    You cannot use Javascript to directly control anything SSI related. Javascript is for the client, SSI is for the server.
    I completely understand that. I try to always use external .js files to have my javascript code be exclusively external. But javascript sometimes needs to be called from within a link or something. For example, when I use onMouseOver, etc. on my menus I can include javascript in my menu.ssi file and it works fine. All that SSI does is put that code on the page and then it get's executed normally via the clientside. Otherwise I'd be forced to include my menu html on every page. And that would be a nightmare for updating purposes.

    I just thought perhaps there could exist some javascript that I would need to call within a link or something and that's why I said I needed javascript that would work with SSI.

    Thank you for your response as well MyDayRegistry. If I come accross some open source code or any code for that matter I'll let you know. Perhaps patrick has the key or can point us to the right code. Hope so.

  5. #5
    Full Member
    Join Date
    October 22nd, 2006
    Posts
    200
    You can do this with javascript:
    First add an id to each of your links then add the javascript which get the current url, checks if the current subdirectory is either port or eng and recreates the new url.

    If you leave the base urls in the a tags people with javascript disabled will be sent to the root of their particular language. The javascript must be included after your anchor tags.

    HTML Code:
    <!--Change Language Div -->
    <div id="language">
    <a id="esid" href="http://www.example.com/index.html" title="Espa&ntilde;ol"><img src="images/spanishFlag.gif" alt="Spanish Flag"></a>
    <a id="enid" href="http://www.example.com/eng/index.html" title="English"><img src="images/english.gif" alt="British Flag" ></a>
    <a id="poid" href="http://www.example.com/port/index.html" title="Portuguese"><img src="images/portuguese.gif" alt="Brazilian Flag"></a>
    </div>
    <script type="text/javascript">
    <!--
    var url=(document.location.href);
    var bits=new Array();
    var enbits=new Array();
    var pobits=new Array();
    var esbits=new Array();
    bits=url.split('/');
    var totalbits=bits.length;
    for (i in bits){
    enbits[i]=bits[i];
    pobits[i]=bits[i];
    esbits[i]=bits[i];
    }
    //if subdirectory is english
    if (bits[totalbits-2]=='eng'){
    pobits[totalbits-2]='port';
    esbits[totalbits-2]=esbits[totalbits-1];
    esbits.pop();
    }
    //if subdirectory is portuguese
    else if (bits[totalbits-2]=='port'){
    enbits[totalbits-2]='eng';
    esbits[totalbits-2]=esbits[totalbits-1];
    esbits.pop();
    }
    else {
    var file=bits[totalbits-1]
    enbits.pop();
    pobits.pop();
    enbits.push("eng",file);
    pobits.push("port",file);
    }
    enurl=enbits.join("/");
    pourl=pobits.join("/");
    esurl=esbits.join("/");
    document.getElementById('esid').href=esurl;
    document.getElementById('poid').href=pourl;
    document.getElementById('enid').href=enurl;
    //->
    </script>
    <!--End Change Language Div-->
    I'm sure someone will be able to improve my script but this work in firefox and IE6

  6. #6
    ABW Ambassador PatrickAllmond's Avatar
    Join Date
    September 20th, 2005
    Location
    OKC
    Posts
    1,219
    Well me being the PHP p.i.m.p. that I am I'd suggest maybe something like this in PHP:

    PHP Code:
    <?php

    // Get the full url for the current page
    $full_url $_SERVER['FULL_URL'] ; 

    // Break it apart into two pieces at the ".com/"
    // ie part 1 = [url]http://www.site.com[/url] and part2 = topics/yadayada
    $temparray explode(".com/",$full_url,2);

    // build the link for portugal with portugal flag image
    $porttemp $temparray[0] . ".com/port/" $temparray[1];
    $portlink "<a href=$porttemp><img src=portflag.gif></a>";

    // put it on the page
    echo $portlink;
    ?>
    Note: I have not tested this. But this looks like the way you are trying to go. If you had this on every page then it should put out a link for the exact same page with the different folders prepended.

    Help?
    ---
    This response was masterly crafted via the fingers of Patrick Allmond who believe you should StopDoingNothing starting today.
    ---
    Focus Consulting is where I roll | Follow @patrickallmond on Twitter
    Search Engine Marketing | Search Engine Optimization | Social Media | Online Video

  7. #7
    Full Member
    Join Date
    October 22nd, 2006
    Posts
    200
    I'd agree the best way would be to use php. But I guess the OP's server wouldn't handle it.

  8. #8
    Newbie G-WebServices's Avatar
    Join Date
    January 13th, 2008
    Posts
    27
    Donk, thatís exactly the code I needed! Youíre the bomb. It works perfectly in IE, Firefox and Safari PC, (Opera 8 doesnít work though --might have javascript disabled by default or something -- but since I took your advice and left the links in the a tag it sends them to the language index. I need to update my opera to version 9.27 to see if my old version is corrupt or has a bug but itís no biggie). Iím happy.

    Patrick, thank you as well. Iím playing around with your code right now to see if I should use it instead but itís giving me some problems so Iíve incorporated Donkís code instead which seems to solve the issue perfectly.

    Again, thank you very much, both of you.

  9. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Do You Let Your Visitors Know They are Leaving Your Site?
    By bettylou in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: May 5th, 2010, 01:13 PM
  2. Do you have a summer oriented site or section?
    By amanda_mytights in forum ShareASale - SAS
    Replies: 1
    Last Post: June 21st, 2006, 05:37 AM
  3. Do you have a Maternity oriented site or section?
    By amanda_mytights in forum ShareASale - SAS
    Replies: 0
    Last Post: May 12th, 2006, 05:31 PM
  4. What web language should I use for my site
    By boltonian in forum Amazon
    Replies: 0
    Last Post: September 1st, 2004, 11:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •