We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    I believe you.
    Could you just explain what makes the "SELECT 22" ?
    Does it select the fields listed after and append the "22" before all rows returned like if it was the content of a first column ?
      • 9130
      • 171 Posts
      Quote from: Jul at Jan 09, 2009, 05:10 AM

      Does it select the fields listed after and append the "22" before all rows returned like if it was the content of a first column ?
      Exactly
        • 15001
        • 697 Posts
        Well, step 2 * from my multilingual solution is done

        (* http://modxcms.com/forums/index.php/topic,31908.msg193862.html#msg193862 )

        There were several mistakes in my code.
        I was forgetting to send the SQl request from withing the while loop.
        There was also a typo with the table name as well as other mistakes.

        This script sets the value of the "match_id" template variable (named doc_id in previous messages).
        <?php
        
        // This code works fine. Run it once and no more before duplicating the node corresponding
        // to the original language.
        
        // Prior running the code, save your MODx database for security reasons.
        // Also set the correct table prefix by replacing the dbprefix string in the code.
        // Also replace the number 22 with the id that was given by MODx to your match_id TV.
           
        /* include connexion parameters */
        require("db_connexion_params.inc.php");
        
        /* connect the MySql server */
        $connexion = mysql_connect($server, $login, $password) or
        die("Impossible to connect server $server");
        echo "$server server connected<br>";
        
        /* connect the database */
        mysql_select_db($db,$connexion) or die("Impossible to connect the $bd database");
        echo "$db database connected<br>";
        
        /* select identifiers of all MODx documents */
        $table = "dbprefix_site_content";
        $field = "id";
        $request= "SELECT $field FROM $table";
        echo $request;
        echo "<br/>";
        $result = mysql_query($request);
        
        $table = "dbprefix_site_tmplvar_contentvalues";
        
        while ($row = mysql_fetch_array($result) ) {
          $id = $row["id"];
          $request = "INSERT INTO $table VALUES (DEFAULT, 22, $id, $id)";
          // 22 is here the number of the TV the document identifier shared by all translations of the document
          // for the document with id $id, set value for TV #22 to $id.
          mysql_query($request) or die("Impossible to insert new row in tabale $table");;
          echo "New row inserted with match_id = ".$id ;
          echo "<hr />";
        }
        
        echo "Closing MySQL connexion<br>";
        mysql_close($connexion) or die("Impossible to close the MySQL connexion.");
        echo "MySql connexion closed.";
        
        ?>

        As step 3 (i.e. duplicating the original language node) is ultra easy, I’ll jump at step 4 and write the snippet to display the language toolbar.

        @etal: I tried your code but could not make it work. I was probably doing some mistake.
        Not so important since the while loop of my script is working fine now.
          • 15001
          • 697 Posts
          Summary :
          Solution for multilingual MODx websites with minimal TV manual edition,
          allowing different document names and aliases for the miscellaneous translations.

          1) Create a T.V. in the template that stores and the same "document id" to all translation of the same document.
          Let’s call this T.V. "doc_id".

          2) Set "doc_id" to the same value as "id" for all documents (before original docs are duplicated).
          I think that this could be done with some batch SQL request.

          3) Duplicate the root node from the original language (i.e. add a translation).
          The values of "doc_id" of the translated docs would remain the same as those from the original document.

          4) Use some code that allows to link documents with the same "doc_id".
          Well, I’ve started implementing step 4.
          First, available languages are printed using a Wayfinder call with this config :
          <?php
          
          $startId='0';
          $level='1';
          
          $outerTpl='@CODE:<div class="langbar" align="right">[+wf.wrapper+]</div>';
          
          $rowTpl='@CODE:<a href="Snippet_Output_Here.html" title="[+wf.linktext+]" >[+wf.linktext+]</a>';
          
          $cssTpl = '@CODE:<link rel="stylesheet" media="all" type="text/css" href="assets/snippets/wayfinder/css/LangBar.css" />';
          
          ?>

          The snippet that should be called from within Wayfinder’s configuration for the "languages bar" :
          <?php
          function ReturnTranslationId ($match_id, $destLang_id) {
            // match_id : value of the match_id TV linking the current document and the translation
            // destLand_id : id of the root document of the destination language
            // match_id_TV : id of the match_id TV 
            
            // 1) Find the id of the match_id TV
            $req = "SELECT id FROM alti_site_tmplvar WHERE name=='match_id';
            $res = mysql_query($req); // return only 1 record
            $match_id_TV = mysql_fetch_row($res); // read the record
            
            // 2) Find all documents with the same match_id value, i.e. known translations.
            $req="SELECT contentid FROM alti_site_tmplvar_contentvalues WHERE (tmplvarid==$match_id_TV AND value==$match_id)";
            $res = mysql_query($req); // return the document identifiers of all known translations.
          
            // 3) Select the document that is in the language the user expects, i.e. the translation.
            while ($id = mysql_fetch_row($result) ) {
          	  // Here we must test if the destination document with id $id
          	  // is a child of the destination language root specified by $destLang_id.
          	  // In this case, the translation was found, return $id as target $id. (This quits the loop.)
          	  // Else loop.
            }
            
            // 4) If no translation was found for the current document$, 
            //    return the id of the homepage for the translation.
            //    This could be improved by checking that $destLang_id is at the first
            //	level of the hierarchy in the document tree.
            return $destLang_id;
            
          } 
          ?>

          As I never used the MODx API until now, I’m not much aware about how I could use it for point 3. undecided
          Maybe I should look at etal’s snippet more carefully, especially the getParents function:
          http://modxcms.com/forums/index.php/topic,25827.0.html
          Of course, any help in coding point 3 above would be much appreciated. grin

          To know the language of each document, I plan to use either regular expression applied to search-engine-friendly URLs, or store it in a "language" T.V.
          Setting the "language" T.V. can be done at a glance for each language root by using the DocManager module.
          I renounced to these ideas.
          There is like a bug in DocManager which makes impossible to set a TV for a branch and all its subnodes.
          (See http://modxcms.com/forums/index.php/topic,31954.0.html for details.)
            • 15001
            • 697 Posts
            I’m currently working on a "LangBar" snippet using the MODx API.
            I plan that Wayfinder won’t be necessary.
            Please wait a little bit for news.