We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50595
    • 32 Posts
    Hello experts

    For a multilingual site I'm working with three different contexts (web, en, it). For this site I'm developing some templates. In those templates I'd like to use output filters like :is=`` that changes output according to the context MODX is using at the time. At https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers) I read about

    [[+placeholder:is=`0`:then=`
    	// code
    `:else=`
    	// code
    `]]
    


    This works for two contexts as far as I can see. But I have three (or even more) contexts.

    Is there a possibility to chain :is / :then / :else filter more than two times? Something like :is / :then / :elseif / :then / :elseif / :then / :else or something like that?

    Greetings

    Ralph

    This question has been answered by Jako. See the first response.

    [ed. note: ralphbolliger last edited this post 10 years, 11 months ago.]
      • 4172
      • 5,888 Posts
      What exactly (examples) do you want to change, depending on the context.
      I'm sure, there are better ways, than using outputfilters for that use-case.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 50595
        • 32 Posts
        Hi Bruno17

        Quote from: Bruno17 at Nov 01, 2015, 02:56 PM
        What exactly (examples) do you want to change, depending on the context.
        I'm sure, there are better ways, than using outputfilters for that use-case.

        Let's say a template contains a pricing table. It tells the customer a product costs «22 Swiss Francs per month» on the English version of the website. On the German version it tells the user «22 Schweizer Franken pro Monat». The content editor (provided by the customer) only has the possibility to change the price via a TV called [[*productPrice]]. If I only have two languages I would code my template like this:

        <div class="price">
        	<p class="pricetag">[[*productPrice]] [[++cultureKey:is=`de`:then=`Schweizer Franken pro Monat`:else=`Swiss Francs per month`]]</p>
        </div>
        


        But now the website supports three languages (de, en, fr). How can I differentiate the :else case between en and fr?

        Greetings

        Ralph
        • discuss.answer
          • 13428 ☆ A M B ☆
          • 1,031 Posts
          Use a lexicon for this.

          Short version: create three files named core/components/whatevername/lexicon/de/default.inc.php, core/components/whatevername/lexicon/en/default.inc.php, core/components/whatevername/lexicon/fr/default.inc.php and fill them with the language keys & values. Create a namespace for whatevername and fill the core path input with {core_path}components/whatevername/. Save the files and refresh the MODX cache. Then you should be able to call them by
          [[%key? &namespace=`whatevername`]]. whatevername should be replaced. [ed. note: Jako last edited this post 10 years, 11 months ago.]
            • 4172
            • 5,888 Posts
            What Jako says.
            This is, what lexicon-entries are for.

            you could also put a snippet 'loadMyLexicon' at the beginning of your template with

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


            called like that:

            [[loadMyLexicon]]


            Then you don't need the namespace in the lexicon-tags and its enough to call it for example with

            [[%francs_per_month]] 





              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 4172
              • 5,888 Posts
              Another way, if you do not want to use lexicons for some reason, could be, to create a snippet 'translate' with

              $cultureKey = $modx->getOption('cultureKey');
              $output = $modx->getOption($cultureKey,$scriptProperties,'');
              
              return $output;


              and call it with:

              [[translate? &de=`Schweizer Franken pro Monat` &en=`Swiss Francs per month`]]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 50595
                • 32 Posts
                Hi Jako & Bruno17

                Thank you for your hints. I will check this out.

                Greetings

                Ralph
                  • 50595
                  • 32 Posts
                  Hey there Bruno17 & Jako

                  I'm having some difficulties. Maybe you will see what I'm doing wrong.
                  I created two folders and files:

                  core/components/i18n/de/default.inc.php
                  core/components/i18n/en/default.inc.php

                  In both files I wrote one single line of code:

                  In core/components/i18n/en/default.inc.php
                  <?php
                  	
                  	$lang['_custom.test'] = 'This is a test.';
                  


                  and in core/components/i18n/de/default.inc.php
                  <?php
                  	
                  	$lang['_custom.test'] = 'Das ist ein Test';
                  


                  In my template I tried to call the string with

                  [[%_custom.test? &namespace=`i18n`]]
                  


                  For some reason I expected that it doesn't work like this. I guess the applications doesn't know my component called i18n. I also added a new translation to core/lexicon/de/default.inc.php and core/lexicon/en/default.inc.php. It didn't work either. What ever I do, the output on front-end is _custom.test only.

                  Best regards

                  Ralph
                    • 4172
                    • 5,888 Posts
                    did you create a namespace?

                    system->namespaces
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 4172
                      • 5,888 Posts
                      and the files should be in

                      core/components/i18n/lexicon/de/default.inc.php

                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!