We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32646
    • 87 Posts
    I was given this idea from Bogdan Günther and it sounded like a great idea if you are using FURLs. If you set everything up the way they recommend in the wiki, things work well. But when you have 100’s of pages, it gets very difficult to map all translated pages.

    Bogdan said: you really need this feature you could use friendly URLs to accomplish this if you use the same alias in both languages:

    Code:
    mysite.com/de/category-10/product-4/variant-17.html
    mysite.com/en/category-10/product-4/variant-17.html

    Then you only have to change the language indicator in the URI.

    That is so obvious and brilliant. So I tried cobbling a solution together. Mostly by copying the Multi-Language wiki.


    All I have to do now is check to see if the page is available and if not, redirect to the main language page. That is where I am now. Can anyone help me? Also, if you wish, please clean up the script. I am a PHP newbie.

    I also created a new TV that shows what language you are in. I made it a radio button, so it is very easy for the user. The value is the ISO 2-letter code.

    English==en||Español==es||Nederlands==nl||Português==pt||Русский==ru||中文==zh

    <?php
    // Most code copied from Multi-language wiki page
    // Thanks to Bogdan Günther for giving me the idea!
    $pageURL = $_SERVER["REQUEST_URI"];
    if ($pageURL == '/') $pageURL = '/en/'; //only here because my start page doesn't have a language designation.
    
    // get current language
    $tv = $modx->getTemplateVar('Lang', "", $modx->documentIdentifier);
    $curlang = $tv['value'];
    
    $langnames = array(
    "en" => "English",
    "es" => "Español",
    "nl" => "Nederlands",
    "pt" => "Português",
    "ru" => "Русский",
    "zh" => "中文"
    );
     
    $output = "";
     
    // loop through language entries
    for ($e = 0; $e < sizeof($langnames); $e++)
    {
    	$lname = current($langnames);
      $target = key($langnames);
      $nPageURL = str_replace('/'.$curlang.'/', '/'.$target.'/', $pageURL); //replace current language folder with target language folder
      
      $image = '<img src="assets/images/flags/'.$target.'.gif" width="16" height="11" alt="'.$target.'" title="'.$lname.'" />';
      if (strlen($output))
      {
        $output .= ' ';
      }
      if ($curlang != $target) { //prevents adding a flag for the current language
      $output .= '<a href="'.$nPageURL.'">'.$image.'</a>';
    }
      next($langnames);
    }
    return $output;
    ?>


    Here is my test site (not fully implemented, because I don’t have any language pages below the home pages yet):

    http://test.valcompanies.com/
      Just learning the ropes.
      • 3785
      • 143 Posts
      I am afraid you will get ready to use custom PHP code only if you pay someone for it. As far as I am used to there are mostly tipps and sample code in the forums. But maybe I have the wrong idea here.

      But I definitely have a tipp for you:
      "es" => "Español",

      Why don’t you use UTF-8 encoding so you can just write:
      "es" => "Español",


      UTF-8 Encoding is ideal for multi-language websites!
        Medianotions – Studio für Webdesign
        http://www.medianotions.de