We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    Quote from: roman.khazizov at Jan 07, 2014, 09:17 AM
    Quote from: BobRay at Jan 07, 2014, 08:16 AM
    Right, but the OP is talking about existing MODX snippets that don't have that capability.

    That said, many of those snippets (e.g. getResources) use Tpl chunk and you could put language tags in those chunks.

    SimpleSearch snippet? I looked on a github page of this snippet and there is lexicons present, actually. The code:

    $this->modx->lexicon->load('sisea:default');

    I'm just not able to find that piece of code. I looked at https://github.com/splittingred/SimpleSearch and in the code for all the SimpleSearch-snippets in Manager.

    Can you Please give me a hint on where to find it so I can try your code-example?
      I think, thererfor I am! But what I am, and why...?
      • 45063
      • 40 Posts
      Quote from: Sylvaticus at Jan 07, 2014, 03:44 PM

      https://github.com/splittingred/SimpleSearch/blob/develop/core/components/simplesearch/model/simplesearch/simplesearch.class.php

      Here. You can find this file in the same path in you MODX installation.
        • 29076
        • 615 Posts
        Quote from: roman.khazizov at Jan 08, 2014, 07:41 AM
        Quote from: Sylvaticus at Jan 07, 2014, 03:44 PM

        https://github.com/splittingred/SimpleSearch/blob/develop/core/components/simplesearch/model/simplesearch/simplesearch.class.php

        Here. You can find this file in the same path in you MODX installation.

        As far as I can tell that's not the working snippet-code. Tried to copy that code into the SimpleSearch-snippet, and the website came up empty.

        Here is the working code :https://github.com/splittingred/SimpleSearch/blob/develop/core/components/simplesearch/elements/snippets/simplesearch.snippet.php.
          I think, thererfor I am! But what I am, and why...?
          • 3749
          • 24,544 Posts
          Sylvaticus, most of the code that does the actual work is in the SimpleSearch class file (roman's link), not the snippet. The snippet "includes" the class and calls its methods. It sounds like you pasted the *class* file code into the snippet, which would definitely cause a crash.

          The class file itself (simplesearch.class.php) should be in this directory:

          core/components/simplesearch/model/simplesearch/

          That's where you need to make the modifications (after restoring the snippet code).

          GitHub is down right now, so I can't check the actual code.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 29076
            • 615 Posts
            Quote from: roman.khazizov at Jan 07, 2014, 09:17 AM


            For language change, create a TV with language parameter (en/no) and before this line, you can add something like this:

            $page = $modx->getObject('modResource', 123); // number of resource that uses this TV
            $lang = $page->getTVValue('lang'); // TV named 'lang'
            $Setting = $modx->getObject('modSystemSetting', 'cultureKey');
            $Setting->set('cultureKey', $lang);


            Finally, insert [[!SimpleSearch]] snippet on page Uncached.

            Thanks for pointing out the right direction for me. After searching around a little bit I found out I hade to use
            		$id = $modx->resource->get('id');
            		$page = $modx->getObject('modResource', $id); // number of resource that uses this TV
            		$lang = $page->getTVValue('lang'); // TV named 'lang'
            		$modx->setOption('cultureKey', $lang); 
            		$this->modx->lexicon->load('sisea:default');


            No it works perfect with your TV-solution. Thanks again! laugh

            The next thing now would be able to set this directly in the snippet-call, as:
            [[!SimpleSearch &lang=`no`]]
            or
            [[!SimpleSearch &lang=`en`]]
            instead of via a TV. [ed. note: Sylvaticus last edited this post 10 years, 3 months ago.]
              I think, thererfor I am! But what I am, and why...?
              • 45063
              • 40 Posts
              Quote from: Sylvaticus at Jan 09, 2014, 05:25 PM


              The next thing now would be able to set this directly in the snippet-call, as:
              [[!SimpleSearch &lang=`no`]]
              or
              [[!SimpleSearch &lang=`en`]]
              instead of via a TV.

              It can be done like this:

              Rewrite simplesearch.class code to the following:

              $modx->setOption('cultureKey', $lang); 
              $this->modx->lexicon->load('sisea:default');


              And add to the simplesearch.snippet at line 77 following:

              $lang = $modx->getOption('lang',$scriptProperties,'en');


              Then, I guess, you should be able to use &lang parameter.

              OR, (if this approach not working) just try to insert this lines directly in simplesearch.class (line 77):

              $lang = $modx->getOption('lang',$scriptProperties,'en');
              $modx->setOption('cultureKey', $lang); 
              $this->modx->lexicon->load('sisea:default');


              Let me know if it's working. [ed. note: roman.khazizov last edited this post 10 years, 3 months ago.]