We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12352
    • 101 Posts
    ah ok, thank you Susan, I’ll try that.

    Still learning the modx slang, but I’m getting there smiley
      Don't believe anything you read on the net. Except this.
      • 11411
      • 2 Posts
      it might be more reasonable to use the switch() instead of so many if()’s

      <?php
      // initialize the $output
      $output ='';
      
      switch ($language) {
          case 'be' :
              $output .='{{introtekst_be}}';
              break;
      
          case 'gb' :
              $output .='{{introtekst_gb}}';
              break;
      
          case 'fr' :
              $output .='{{introtekst_fr}}';
              break;
      
          default :
              $output .='{{default_lang_chunk}}';
      }
      
      return $output;
      ?>
      


      more about switch @ http://ee.php.net/manual/en/control-structures.switch.php


      I hope this helps smiley
        • 12352
        • 101 Posts
        Am I missing something here? I just can’t get it to work.

        Ok, I’ve got a snippet called introtekst and I put this in the template: [!introtekst!]

        I’ve got 4 chunks: introtekst_be, introtekst_gb, introtekst_fr, introtekst_default

        This is the snippet, following your suggestions:

        <?php
        // initialize the $output
        $output ='';
        
        switch ($language) {
            case 'be' :
                $output .=$modx->getChunk('introtekst_be');
                break;
        
            case 'gb' :
                $output .=$modx->getChunk('introtekst_gb');
                break;
        
            case 'fr' :
                $output .=$modx->getChunk('introtekst_fr');
                break;
        
            default :
                $output .=$modx->getChunk('introtekst_default');
        }
        
        return $output;
        ?>
        


        Also tried following snippet:

        <?php
        // initialize the $output
        $output ='';
        
        switch ($language) {
            case 'be' :
                $output .='{{introtekst_be}}';
                break;
        
            case 'gb' :
                $output .='{{introtekst_gb}}';
                break;
        
            case 'fr' :
                $output .='{{introtekst_fr}}';
                break;
        
            default :
                $output .='{{introtekst_default}}';
        }
        
        return $output;
        ?>


        And this one:
        <?php
        // initialize the $output
        $output ='';
        
        if ($language == 'be') {
            $output .='{{introtekst_be}}';
        }
        if ($language == 'gb') {
            $output .='{{introtekst_gb}}';
        }
        if ($language == 'fr') {
            $output .='{{introtekst_fr}}';
        }
        if ($language != 'be' || $language != 'gb' || $language != 'fr') {
            $output .='{{introtekst_default}}';
        }
        
        return $output;
        ?>
        


        It only returns the default text
          Don't believe anything you read on the net. Except this.
          • 12352
          • 101 Posts
          Ok, I finally got it!

          I had to pass the language variable to the snippet and put this in the template:
          [!introtekst? &language=`[+language+]`!]

          With following snippet:
          <?php
          // initialize the $output
          $output ='';
          
          switch ($language) {
              case 'be' :
                  $output .='{{introtekst-be}}';
                  break;
          
              case 'gb' :
                  $output .='{{introtekst-gb}}';
                  break;
          
              case 'fr' :
                  $output .='{{introtekst-fr}}';
                  break;
          
              default :
                  $output .='{{introtekst-default}}';
          }
          
          return $output;
          ?>
          

            Don't believe anything you read on the net. Except this.
            • 31034
            • 6 Posts
            I’m completely new to MODx and while composing requirements list for CMS to use (stopped on MODx already) made a note that CMS should have the ability to determine user’s language based on Accept-Language HTTP request header (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4). So here’s my two humble questions:
            1) Where $language variable in presented PHP code is defined and how it receives its value ("en", "fr" or anything), I mean, what part of MODx engine (if any) do this?
            2) Is it possible for a snippet to reach HTTP request to read Accept-Language header and action accordingly?
              MODx Revo 2.0.0 beta 4
              Shameless MODx newbie
              • 22851
              • 805 Posts
              This functionality isn’t part of the core MODx. However there is a multilingual solution, YAMS, that has this functionality built in.

              If you choose ’current else browser’ as the language detection mode and it is not clear from the URL they have chosen which language they wanted (eg: http://mysite.com/), then they will be redirected to a page in the last language they visited (using a cookie), or, if they haven’t yet visited a page before the language will be chosen by looking at the AcceptLanguage headers (eg: redirection to http://mysite.com/en/).
                YAMS: Yet Another Multilingual Solution for MODx
                YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                • 349
                • 76 Posts
                Hi. I already implemented a solution for this in my tutorial (but it isn´t explained).
                See the line
                if (file_exists("assets/languages/$language.php")) include_once "assets/languages/$language.php";

                in the "language" snippet?
                It includes a file with your own defined placeholders for every language.
                So make a file for example: "de.php" in assets/languages folder (create the folder first if it doesn´t exist)
                and define a placeholder:
                $modx->setPlaceholder("to_top",'go to top of page');

                now you can use your placeholder anywhery on your site.

                Hope i could help.

                Aceman