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

    i set various language-headlines with "is then":

    [[++cultureKey:is=`de`:then=`Ihre Ansprechpartner`:else=``]]
    [[++cultureKey:is=`en`:then=`Contact persons`:else=``]]
    [[++cultureKey:is=`es`:then=`Contacto`:else=``]]
    [[++cultureKey:is=`ru`:then=`Kонтактные лица`:else=``]]
    


    Question: how is possible to set the example in one line and reduced?

    This question has been answered by multiple community members. See the first response.

      • 17301
      • 932 Posts
      You could write a php snippet that will act as a switch case but that would only be suited really for this line of text. It looks as though you're making a multilingual site? You may want to look into migxmultilang or just using a htaccess file to forward your visitors onto the correct context for their language.
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 51347
        • 82 Posts
        Thanks for answer,

        yes that is a multilingual site. I using the Babel-Tool and all the context (and htaccess) works fine. I just try to minimize codes and im php-newby..
        • discuss.answer
          • 3749
          • 24,544 Posts
          A snippet called Contacts should do it:

          [[!Contacts]]



          /* Contacts snippet */
          $cultureKey = $modx->getOption('cultureKey');
          
          $messages = array(
              `de` =>`Ihre Ansprechpartner`,
              `en` => `Contact persons`,
              `es` => `Contacto`,
              `ru`:then=`Kонтактные лица`,
          );
          
          return isset($messages[$cultureKey]? $messages[$cultureKey] : '';
          


          Another way to go, if you already have those languages in the core namespace, would be to create 4 new entries, one for each language, in the core namespace and create a lexicon entry for message with the key 'contacts' in the default topic. If you don't have those languages, you could add them.

          Then, on your page, use this tag:

          [[!%contacts? &namespace=`core` &language=`[[++cultureKey]]` &topic=`default` ]]


          This second method might be a little slower, but it would allow you to create other language-specific messages without creating a custom snippet for each one.
            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
            • 51347
            • 82 Posts
            Nice BobRay,

            thank you so much!

            -------

            I have error with ` in this snippet, thats my new version:

            <?php
            $cultureKey = $modx->getOption('cultureKey');
             
            $messages = array(
                "de" =>"Ihre Ansprechpartner",
                "en" => "Contact persons",
                "es" => "Contacto",
                "ru":then="Kонтактные лица",
            );
             
            return isset($messages[$cultureKey]? $messages[$cultureKey] : "";
            


            8:	Syntax error, unexpected ':', expecting ')'
            11:	Syntax error, unexpected '?', expecting ',' or ')'
            



            Can you help me? [ed. note: joe-petts last edited this post 6 years, 9 months ago.]
            • discuss.answer
              • 4172
              • 5,888 Posts
              why not using the MODX - lexicon for translations like that?

              your line should have been:

              return isset($messages[$cultureKey])? $messages[$cultureKey] : "";
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
              • discuss.answer
                • 17301
                • 932 Posts
                <?php
                $cultureKey = $modx->getOption('cultureKey');
                  
                $messages = array(
                    "de" => "Ihre Ansprechpartner",
                    "en" => "Contact persons",
                    "es" => "Contacto",
                    "ru" => "Kонтактные лица",
                );
                  
                return isset($messages[$cultureKey])? $messages[$cultureKey] : "";
                [ed. note: lkfranklin last edited this post 6 years, 9 months ago.]
                  ■ email: [email protected] | ■ website: https://alienbuild.uk

                  The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                  • 51347
                  • 82 Posts
                  Quote from: Bruno17 at Jun 29, 2017, 07:58 AM
                  why not using the MODX - lexicon for translations like that?

                  I try it in the future smiley


                  Thank you LK, it works!