We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43099
    • 38 Posts
    Hi I think this is a fairly easy question, hope someone with slightly more coding knowledge could help out.

    I am working with the SPForm snippet, and need to set the language. The SPForm allows 5 different languages, and default is to take the default language from the modx install. Howoever my modx install is in English but the main site is in Chinese, plus I have an English version as well so I can't jerry-rig this one. As a non-coder, you wouldn't believe the work I will do to get around the need to so a bit of coding.

    The SPForm snippet contains this section to set the language:

    $language = !empty($spfconfig['language'])
        ? $spfconfig['language'] . ':'
        : '';
    
    /* allow different language than used in Manager */
    if (!empty($spfconfig['language'])) {
      $modx->setOption('cultureKey', $spfconfig['language']);
    }
    
    $modx->lexicon->load($language . 'spform:default');


    So its a little complicated as I need different parts of the site to use different languages, but I need to set the language to 'nl', and then I will modify the properties of the nl group to Chinese.

    I have no experience with php (this is php right) and have had trouble searching for the answer.

    Should it be

    $language = !nl($spfconfig['language'])
        ? $spfconfig['language'] . ':'
        : '';
    
    or maybe 
    
    $language = !empty($spfconfig['nl'])
    ? $spfconfig['nl'] . ':'
    : '';
    Or is it not so obvious a solution? Any help would be appreciated. Thanks!

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

      • 4172
      • 5,888 Posts
      can't you just set the language with

      &language=`nl`


      or with a TV

      &language=`[[*yourLang]]`


      or with a snippet, which gets the correct language for each situation

      &language=`[[getMyLanguage]]`






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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 43099
        • 38 Posts
        Yes I tried by putting the &language property in the snippet call, but it leads to the form not appearing on the page anymore.

        The other two don't work as I am trying to choose a language other than the language of the modx install, not the defaul language at all.
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          If you have different contexts for different languages, you could set your cultureKey system setting on the contexts, and it will use that one without having to hack spform or pass the &language option.

          At any rate I don't see why you would need to change the spform snippet? Try again with the &language property (or context settings) and if that doesn't work, post the exact snippet call.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 43099
            • 38 Posts
            Quote from: markh at May 19, 2013, 06:56 AM
            If you have different contexts for different languages, you could set your cultureKey system setting on the contexts, and it will use that one without having to hack spform or pass the &language option.

            At any rate I don't see why you would need to change the spform snippet? Try again with the &language property (or context settings) and if that doesn't work, post the exact snippet call.

            Ah, ok contexts sound like a better way, because even if I successfully hack SPForm, I still need it to have two different languages in different places. Let me look at the cultureKey and contexts before doing anything rash...

            Thanks for the advice Gents! Appreciated!
            • discuss.answer
              • 3749
              • 24,544 Posts
              Quote from: d_u_n. at May 19, 2013, 03:53 AM
              Yes I tried by putting the &language property in the snippet call, but it leads to the form not appearing on the page anymore.

              That should work. I wonder if you just had an error in the tag (like leaving out the question mark or not using back-ticks).

              [[!SPForm? &language=`nl`]]
                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
                • 43099
                • 38 Posts
                Quote from: BobRay at May 20, 2013, 02:48 AM
                Quote from: d_u_n. at May 19, 2013, 03:53 AM
                Yes I tried by putting the &language property in the snippet call, but it leads to the form not appearing on the page anymore.

                That should work. I wonder if you just had an error in the tag (like leaving out the question mark or not using back-ticks).

                [[!SPForm? &language=`nl`]]

                Ah! It works now!

                I think I was missing the question mark after the SPForm, perhaps that's what went wrong, the back-ticks look fine.

                Ok, so I know how to hack it, now I have to learn about contexts and see how to approach this problem...but now the SPForm is good to go, I can just call the lingo I want on different pages. That's perfect and avoids the whole context thing if I don't need it otherwise.

                Thanks BobRay! I will get another post out about how to configure SPForm up soon!
                  • 3749
                  • 24,544 Posts
                  Leaving out the question mark is listed here: http://bobsguides.com/insidious-modx-errors.html wink

                    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