Dynamic English/French links

Discussion in 'HTML' started by Jim Royal, Jan 12, 2005.

  1. Jim Royal

    Jim Royal Guest

    Living in Montreal, I am required to produce web content in both
    official languages. So, my English sites contain links to French
    content, and vice versa.

    For database-driven sites, pulling up the content in the right language
    is merely part of the query. But for static sites, all I've been able
    to do is provide a link to the main page in the alternate language, but
    that's a bit awkward for the site visitor.

    Is there a way to pick up the URL for the current page, rewrite it on
    the fly, and call up the equivalent page in the alternate language? For
    example, to change this:

    /en/services/general.shtml

    into this:

    /fr/services/general.shtml

    Javascript? PHP?

    Any suggestions are welcome.

    --
    Jim Royal
    "Understanding is a three-edged sword"
    http://JimRoyal.com
     
    Jim Royal, Jan 12, 2005
    #1
    1. Advertising

  2. Jim Royal

    Philip Ronan Guest

    Jim Royal wrote:

    > Living in Montreal, I am required to produce web content in both
    > official languages. So, my English sites contain links to French
    > content, and vice versa.
    >
    > For database-driven sites, pulling up the content in the right language
    > is merely part of the query. But for static sites, all I've been able
    > to do is provide a link to the main page in the alternate language, but
    > that's a bit awkward for the site visitor.


    But is it really all that likely your visitors will want to look at BOTH
    languages? Just one or the other, surely?

    I think the best option would be to use a LINK element and let the UAs deal
    with it or not as they see fit. Something like this should do:

    <LINK title="French version" type="text/html" rel="alternate" hreflang="fr"
    href="/fr/services/general.shtml">

    (see <http://www.w3.org/TR/REC-html40/struct/links.html#h-12.3.3>.)

    Alternatively, if you're using an Apache server you should consider using
    its content negotiation features.

    > Is there a way to pick up the URL for the current page, rewrite it on
    > the fly, and call up the equivalent page in the alternate language? For
    > example, to change this:
    >
    > /en/services/general.shtml
    >
    > into this:
    >
    > /fr/services/general.shtml
    >
    > Javascript? PHP?


    If you want to do it this way, add a form with a select menu
    ("French","English") and process it using client-side javascript (based on
    the value of location.href) or server-side PHP (based on the value of
    $_SERVER[¹HTTP_REFERER¹]).

    Phil

    --
    phil [dot] ronan @ virgin [dot] net
    http://vzone.virgin.net/phil.ronan/
     
    Philip Ronan, Jan 12, 2005
    #2
    1. Advertising

  3. Jim Royal

    Guest

    Of course. Move your files to .php instead and use
    $_SERVER["SCRIPT_NAME"] or $_SERVER["PHP_SELF"] to get the current
    document name, and write the links to other languages accordingly.
    You'll need to break it up using explode() and then replace the
    language array element with the target language identifier.

    --
    Hywel
     
    , Jan 12, 2005
    #3
  4. Jim Royal

    Jan Faerber Guest

    Jim Royal wrote:


    > Javascript? PHP?


    Possible solutions:

    #) The user can set the language and it will be saved in a cookie,
    so when he comes again the selected language can be remembered.

    #) The user can not set the language - it will be automatically detected.





    --
    Jan

    http://linux.janfaerber.com
     
    Jan Faerber, Jan 13, 2005
    #4
  5. Jim Royal

    Jim Royal Guest

    In article <BE0AA085.28556%>, Philip Ronan
    <> wrote:

    > But is it really all that likely your visitors will want to look at BOTH
    > languages? Just one or the other, surely?


    Often true, but not always. However, my thought is for people entering
    into the site via deep linking. It would be nice to be able to flip the
    page to the alternate language without forcing people to try and guess
    where in the site hierarchy the page is located.

    > I think the best option would be to use a LINK element and let the UAs deal
    > with it or not as they see fit. Something like this should do:
    >
    > <LINK title="French version" type="text/html" rel="alternate" hreflang="fr"
    > href="/fr/services/general.shtml">


    Interesting. However, this would require encoding the URL manually into
    each page, which is just as much work as making manual HREFs.

    > Alternatively, if you're using an Apache server you should consider using
    > its content negotiation features.


    I will look into this.

    > > Is there a way to pick up the URL for the current page, rewrite it on
    > > the fly, and call up the equivalent page in the alternate language?

    >
    > If you want to do it this way, add a form with a select menu
    > ("French","English") and process it using client-side javascript (based on
    > the value of location.href) or server-side PHP (based on the value of
    > $_SERVER[¹HTTP_REFERER¹]).


    This is probably what I'll do in the short term. Thanks muchly for the
    input.

    --
    Jim Royal
    "Understanding is a three-edged sword"
    http://JimRoyal.com
     
    Jim Royal, Jan 13, 2005
    #5
  6. Jim Royal

    Jim Royal Guest

    In article <>,
    <> wrote:

    > Of course. Move your files to .php instead and use
    > $_SERVER["SCRIPT_NAME"] or $_SERVER["PHP_SELF"] to get the current
    > document name, and write the links to other languages accordingly.
    > You'll need to break it up using explode() and then replace the
    > language array element with the target language identifier.


    I'll keep this in mind for the future. Thanks.

    --
    Jim Royal
    "Understanding is a three-edged sword"
    http://JimRoyal.com
     
    Jim Royal, Jan 13, 2005
    #6
  7. Jim Royal

    Jim Royal Guest

    In article <ktrFd.8053$>, Jan Faerber
    <jancfaerber_spider@monkey_hotmail.com> wrote:
    > #) The user can set the language and it will be saved in a cookie,
    > so when he comes again the selected language can be remembered.
    >
    > #) The user can not set the language - it will be automatically detected.


    I don't think either is a good idea, frankly. This is not like a
    selection for country in an e-commerce site where alternate country
    selections would be of no use. Some people do indeed want to be able to
    see both.

    --
    Jim Royal
    "Understanding is a three-edged sword"
    http://JimRoyal.com
     
    Jim Royal, Jan 13, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F. GEIGER
    Replies:
    3
    Views:
    373
    F. GEIGER
    Jul 18, 2004
  2. F. GEIGER
    Replies:
    3
    Views:
    816
    F. GEIGER
    Aug 6, 2004
  3. Pater Maximus
    Replies:
    1
    Views:
    348
    Ian Parker
    Oct 20, 2004
  4. Tim Golden
    Replies:
    1
    Views:
    342
    Pater Maximus
    Oct 20, 2004
  5. Tim Golden
    Replies:
    2
    Views:
    458
    Roger Upole
    Oct 21, 2004
Loading...

Share This Page