We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7872
    • 14 Posts
    Colleagues.

      Please help mod multilanguage, which I miraculously found on the Internet for ours with you the engine modx.


      The source code is as follows:

    <?php
    $mainurl["ru"] = $modx->makeURL(2);
    $mainurl["en"] = $modx->makeURL(3);
    $baseurl=$modx->config["base_url"];
    $templateId["ru"] = 13;
    $templateId["en"] = 14;
    $template=$modx->documentObject['template'];
    
    function BaseReplace ($baseurl, $url) {
    global $modx;
    $url = str_replace(
        $modx->config['friendly_url_suffix'],
        "", $url);
    if ($baseurl == "/") return substr ($url, 1);
    else return str_replace ($baseurl, "", $url);
    }
    
    switch ($template) {
    
    case $templateId["ru"]:
    $output='                               <td width="5"></td>
                                            <td width="*"></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="active_menu" align="center"><a href="#" class="mainmenu_a"><img width="20" src="assets/templates/enzim/i/flags/ru.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a class="nonmainmenu_a" href="';
    $url = str_replace ("/ru/", "/en/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["en"];
    $output.='" title="English" ><img width="20" src="assets/templates/enzim/i/flags/en.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a href="#" class="nonmainmenu_a"><img width="20" src="assets/templates/enzim/i/flags/fr.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>';
    break;
    
    case $templateId["en"]:
    $output='                               <td width="5"></td>
                                            <td width="*"></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a class="mainmenu_a" href="';
    $url = str_replace ("/en/", "/ru/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["ru"];
    $output.='" title="по-русски" ><img width="20" src="assets/templates/enzim/i/flags/ru.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="active_menu" align="center"><a href="#" class="mainmenu_a"><img width="20" src="assets/templates/enzim/i/flags/en.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a href="#" class="mainmenu_a"><img width="20" src="assets/templates/enzim/i/flags/fr.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>';
    break; 
    }
    return $output;
    ?>


    As you can see, the module includes support for bilingualism. It is logical to assume that you can make and support for three languages ​​...

      My non-working hack is as follows:

    <?php
    $mainurl["ru"] = $modx->makeURL(2);
    $mainurl["en"] = $modx->makeURL(3);
    $mainurl["fr"] = $modx->makeURL(4);
    $baseurl=$modx->config["base_url"];
    $templateId["ru"] = 7;
    $templateId["en"] = 6;
    $templateId["fr"] = 23;
    $template=$modx->documentObject['template'];
    
    function BaseReplace ($baseurl, $url) {
    global $modx;
    $url = str_replace(
        $modx->config['friendly_url_suffix'],
        "", $url);
    if ($baseurl == "/") return substr ($url, 1);
    else return str_replace ($baseurl, "", $url);
    }
    
    switch ($template) {
    
    case $templateId["ru"]:
    $output='                               <td width="5"></td>
                                            <td width="*"></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="active_menu" align="center"><a href="#" class="mainmenu_a"><img width="20" src="assets/templates/enzim/i/flags/ru.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a class="nonmainmenu_a" href="';
    $url = str_replace ("/ru/", "/en/", "/fr/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["en"];
    $output.='" title="English" ><img width="20" src="assets/templates/enzizm/i/flags/en.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a class="nonmainmenu_a" href="';
    $url = str_replace ("/ru/", "/en/", "/fr/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["fr"];
    $output.='" title="Fran?ais" ><img width="20" src="assets/templates/enzim/i/flags/fr.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>';
    break;
    
    case $templateId["en"]:
    $output='                               <td width="5"></td>
                                            <td width="*"></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a class="mainmenu_a" href="';
    $url = str_replace ("/en/", "/ru/", "/fr/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["ru"];
    $output.='" title="по-русски" ><img width="20" src="assets/templates/enzim/i/flags/ru.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="active_menu" align="center"><a href="#" class="mainmenu_a"><img width="20" src="assets/templates/enzim/i/flags/en.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a class="nonmainmenu_a" href="';
    $url = str_replace ("/ru/", "/en/", "/fr/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["fr"];
    $output.='" title="Fran?ais" ><img width="20" src="assets/templates/enzim/i/flags/fr.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>';
    break; 
    
    case $templateId["fr"]:
    $output='                               <td width="5"></td>
                                            <td width="*"></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a class="mainmenu_a" href="';
    $url = str_replace ("/en/", "/ru/", "/fr/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["ru"];
    $output.='" title="по-русски" ><img width="20" src="assets/templates/enzim/i/flags/ru.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="active_menu" align="center"><a class="nonmainmenu_a" href="';
    $url = str_replace ("/ru/", "/en/", "/fr/", 
         $modx->makeURL($modx->documentIdentifier));
    if (array_key_exists(BaseReplace ($baseurl,$url), 
         $modx->documentListing))
            $output.=$url;
    else
            $output.=$mainurl["en"];
    $output.='" title="English" ><img width="20" src="assets/templates/enzim/i/flags/en.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>
                                            <td width="*" height="50" class="nonactive_menu" align="center"><a href="#" class="mainmenu_a"><img width="20" src="assets/templates/enzim/i/flags/fr.png" /></a></td>
                                            <td width="2" class="menu_bor" height="50"></td>';
    break; 
    }
    return $output;
    ?>


    Unfortunately, never I am a programmer, so my hack did not work. Although it seems to me that everything is logical.

    Please help - you need to do to earn the support of three languages.
      • 1343 ☆ A M B ☆
      • 2,213 Posts
      Hello,

      You might want to give YAMS a try, as it should do the job out of the box.
        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting