We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36624
    • 535 Posts
    Quote from: sketchi at Apr 09, 2013, 06:33 AM
    Thanks to some awesome programming by kallteknik.se I've now got a multilanguage Gallery. Yippee!

    If anyone else needs this snippet, get in touch!

    Woa ! Looks very interesting ! Can you share with the community or do i need to contact you in private ?
      CTRL+SHIFT+U - Clear Cache
      CTRL+SHIFT+H - Hiding Heft Panel
      CTRL+SHIFT+N - Fast Create Resource
      CTRL+ALT+P - Preview Recource (in edit resorce window)
      CTRL+ALT+S - Save
      • 38740
      • 45 Posts
      Hi, the snippet i wrote extracts the text matching the current culturalkey based on the dividers that is put in the string. So one put all languageversions in the same field.

      Feel free to use if you like smiley

      /JohnJohn22

      <?php
      /**
       * lanstrip snippet to output different languages, e.g. in Gallery templates.
       * The snippet displays the text matching the current "cultureKey".
       * Can be used anywhere - in chunks, templates etc.
       * The default text must be written first, without a preceeding "#" - this text is used if no matching cultureKey is found.
       * To make the Gallery snippet display a text in different languages, the editor enters the album title like this:
       * "Blå båt #en Blue boat #de Blau Boot"
       * In the gallery item chunk the snippet is called like this:
       * [[lanstrip? &text=`[[+name]]`]]
       *
       * @version 1.0
       * @author Roger Käll (kallteknik.se)
       *
       * @example [[lanstrip? &text=`Svenska #en Engelska #de Tyska`]] or when using a property [[lanstrip? &text=`[[+name]]`]]
       * 
       */
      
      // ----- Get current culturekey (sv,en,de...)
      $cKey = $modx->getOption('cultureKey') ; //<--></-->
      
      // ----- Find current key in text
      $start = strpos($text, "#".$cKey);
      
      // ----- If none print to first "#" and return
      if(!$start){
          echo $start;
          $end = strpos($text, "#");
          if($end==false){echo $text; return;};
          echo substr($text,0,$end);
          return;
          };
          
      $start = $start + 4;
      
      // ----- Find next key (if any)
      $end = strpos($text,"#",$start);
      
      // ----- If no end set end to stringlength
      if(!$end){$end = strlen($text);};
      
      // ----- Print result
      echo substr($text,$start,$end-$start);
      
        ____________________________________________________
        • 36624
        • 535 Posts
        Very smart idea ! Thanx for your share !
          CTRL+SHIFT+U - Clear Cache
          CTRL+SHIFT+H - Hiding Heft Panel
          CTRL+SHIFT+N - Fast Create Resource
          CTRL+ALT+P - Preview Recource (in edit resorce window)
          CTRL+ALT+S - Save