• Hi,

    I have an English website. https://www.mysite.ch

    This has evolved since creation and for several reasons, I need a German copy of the same site.

    The german website is: https://www.mysite-de.ch

    There is a menu and I’d like to have “DE” on the English site and “EN” on the German site. So far so good.

    So, if the enduser is looking at the English page:

    https://www.mysite.ch/about-us

    and clicks on “DE”, the user needs to be redirected to:

    https://www.mysite-de.ch/about-us

    A bit of clever coding, slightly different on both sites should then do the trick.

    Any suggestions?

Viewing 7 replies - 1 through 7 (of 7 total)
  • If it’s a copy, don’t they have different databases and therefore you could edit the menus separately?

    Thread Starter mcaine

    (@mcaine)

    That is correct. They are separate databases – in fact completely separate installations.

    The menu (that goes across the page) is the same on all pages/posts. Currently around 40.

    The point is this: When I add a page to the English site, I then copy it and create the same page, but in German, on the german site.

    eg We add a page called “read-all-about-it” to both sites:

    https://www.mysite.ch/read-all-about-it
    https://www.mysite-de.ch/read-all-about-it

    The menu should not have to change. When the menu “DE” or “EN” is pressed the code should simply take the URL of the current page and add “-de” or remove “-de” respectively.

    Ah, I understand your point now.
    Yes, you’ll need a bit of coding.

    this is not the best way to do it, I’m sure, and I didn’t tested it, just writing on the top of my head, but maybe if you had this (or some variation of this) to the top of your header.php file, it might work:

    <?php
    if (isset($_GET['lang'])) {
       if($_GET['lang'] == "de") {
         header('Location: https://www.mysite-de.ch'.$_SERVER['PHP_SELF']);
       }
       if($_GET['lang'] == "en") {
         header('Location: https://www.mysite.ch'.$_SERVER['PHP_SELF']);
       }
    }
    ?>

    And, the links for the EN|DE should be ?lang=en and ?lang=de

    But this is not the perfect way to do it, but i think you can get an idea of how to achieve it.

    Thread Starter mcaine

    (@mcaine)

    Hi Carlos,

    Thanks for the tip.

    Actually, the menu across the top of each page/post, on the English site is:

    Our Story | Courses | Register | Trainers | DE

    Then the German site is:

    Unsere Geschichte | Kurse | Registieren | Dozente | EN

    So the event is a click on the menu item, not on a locale language setting.

    Is the challenge getting clearer?

    if you’re using the menu builder option on wordpress, you can make the DE / EN links a custom link with the values above, no?

    you can also use javascript, something like:

    <a href="#" onclick="changelang()">DE</a>

    and create the js function similar to this:

    function changelang() {
    window.location("https://www.mysite.de"+location.pathname);
    }
    Thread Starter mcaine

    (@mcaine)

    Ah ha… that looks promising. Thank you. I’ll have a go and will let you know.

    Thank you once again.

    Thread Starter mcaine

    (@mcaine)

    Hi,

    Actually resolved it like this… but your suggestions got me there! I now have a floating “EN” that is at the top-right of the page.

    in style.css, added:

    .header_button {
    position: absolute;
    right: 0px;
    top: -160px;
    z-index: 99;
    }

    then in the header.php of the German site, we added:

    <div style="float:right;" class="header_button"><a href="<?php $Path=$_SERVER['REQUEST_URI']; echo 'https://www.xxx.ch'.$Path; ?>"><span style="color: #ff6600;">EN</span></a></div>

    The English would be the same but refer to https://www.xxx-de.ch.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Link an English Site to a German Site via a Menu’ is closed to new replies.