We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47243
    • 30 Posts
    Hi!
    Guys, I'd love to know exactly how you manage to get the translation of of a multiselect listbox TV.
    Nevertheless I found a solution which doesn't seem nice but works.
    Here it is

    So I created a namespace for my website and then 2 entries with the same name: "myTVContent" (one for "en" and the other for "fr")
    At first I just then put [[!%myTVContent? &namespace=`myNamespace` &topic=`default`]] in the input value for the multiselect listbox TV

    but it wouldn't process my lexicon , so I use @EVAL like this:
    @EVAL $modx->lexicon->load('myNamespace:default');return $modx->lexicon('myTVContent');

    would like to know what you think about this solution.
    Now if I want to add new categories, I will have to add it at the end and be careful that both translation have similar elements separated by ||.

    regards
      • 47243
      • 30 Posts
      Hi!
      Guys, I'd love to know exactly how you manage to get the translation of of a multiselect listbox TV.
      Nevertheless I found a solution which doesn't seem nice but works.
      Here it is

      So I created a namespace for my website and then 2 entries with the same name: "myTVContent" (one for "en" and the other for "fr")
      At first I just then put [[!%myTVContent? &namespace=`myNamespace` &topic=`default`]] in the input value for the multiselect listbox TV

      but it wouldn't process my lexicon , so I use @EVAL like this:
      @EVAL $modx->lexicon->load('myNamespace:default');return $modx->lexicon('myTVContent');

      would like to know what you think about this solution.
      Now if I want to add new categories, I will have to add it at the end and be careful that both translation have similar elements separated by ||.

      regards
        • 16899
        • 284 Posts
        Quote from: robotpapier at Apr 15, 2014, 01:41 PM
        Hi!
        Guys, I'd love to know exactly how you manage to get the translation of of a multiselect listbox TV.
        Nevertheless I found a solution which doesn't seem nice but works.
        Here it is

        So I created a namespace for my website and then 2 entries with the same name: "myTVContent" (one for "en" and the other for "fr")
        At first I just then put [[!%myTVContent? &namespace=`myNamespace` &topic=`default`]] in the input value for the multiselect listbox TV

        but it wouldn't process my lexicon , so I use @EVAL like this:
        @EVAL $modx->lexicon->load('myNamespace:default');return $modx->lexicon('myTVContent');

        would like to know what you think about this solution.
        Now if I want to add new categories, I will have to add it at the end and be careful that both translation have similar elements separated by ||.

        regards

        On your namespace plugin put these values... put priority 1:
        OnHandleRequest \ System \ Default \ 1

        If you have you namespaces loading by default and with the values i mentioned above all you need to do is put the namespace in this format where you want your translated content [[%myTVContent]].

        Ahhh, do not forget to clear cache in every changes that you´ll do in your translation files.

        In a select box all you need to do is:

        <select>
           <option>[[%namespace.1]]</option>
           <option>[[%namespace.2]]</option>
           <option>[[%namespace.3]]</option>
        </select>
        


        But tell me something, before everything, did you create a namespace entry under System > Namespaces? [ed. note: legues last edited this post 12 years, 5 months ago.]
          • 47243
          • 30 Posts
          Hi, thanks for your fast reply!
          Yes, I create a namespace and filled in some entries in the default topic.
          I do not have a plugin for what I need to do, how and where can I load the onHandleRequest to benefit the format without the parameters?

          Indeed, I also added the index number (myOption==1||mySecondOption==2 ...), I found that what was saved in modx when selecting among a list of options is the value. So when I save the same option in two different language context, I had to different options saved, but they are the same, just in 2 different language.

          For now what I did is creating a snippet that convert the number to the category name like this:

          [[+theNumberOfMyOption:numToCategoryName]]

          the snippet numTocategoryName :

          <?php
          $modx->lexicon->load('myNameSpace:default');
          switch($input){
          	case '1': $categoryName = $modx->lexicon('MyOption1'); break;
          	case '2': $categoryName = $modx->lexicon('MyOption2'); break;
          }
          echo $categoryName;
          


          filled the entries (MyOption1, MyOption2) in the 2 language I need.
          And let Babel do the cultureKey detection

          But I still want to know though the onHandleRequest

          And what do you think of my solution? Besides, was wondering if it is ok that the lexicon->load is beeing called several times on the same page?
            • 47243
            • 30 Posts
            ok nevermind for the onHandleRequets, I think I got, just re-read the previous post smiley
              • 16899
              • 284 Posts
              Quote from: robotpapier at Apr 15, 2014, 04:27 PM
              Hi, thanks for your fast reply!
              Yes, I create a namespace and filled in some entries in the default topic.
              I do not have a plugin for what I need to do, how and where can I load the onHandleRequest to benefit the format without the parameters?

              Indeed, I also added the index number (myOption==1||mySecondOption==2 ...), I found that what was saved in modx when selecting among a list of options is the value. So when I save the same option in two different language context, I had to different options saved, but they are the same, just in 2 different language.

              For now what I did is creating a snippet that convert the number to the category name like this:

              [[+theNumberOfMyOption:numToCategoryName]]

              the snippet numTocategoryName :

              <!--?php
              $modx--->lexicon->load('myNameSpace:default');
              switch($input){
              	case '1': $categoryName = $modx->lexicon('MyOption1'); break;
              	case '2': $categoryName = $modx->lexicon('MyOption2'); break;
              }
              echo $categoryName;
              


              filled the entries (MyOption1, MyOption2) in the 2 language I need.
              And let Babel do the cultureKey detection

              But I still want to know though the onHandleRequest

              And what do you think of my solution? Besides, was wondering if it is ok that the lexicon->load is beeing called several times on the same page?

              No!!!!

              Create a plugin, for example,, with your namespace name and then paste this code:

              <?php
               
              if($modx->context->get('key') == 'mgr' || $modx->event->name != 'OnHandleRequest') { return ''; }
               
              $modx->lexicon->load('myNameSpace:default');
              


              Then under the system Events tab check OnHandleRequest option and put the attributes (I guess you just need to double click on the last field and insert 1:

              OnHandleRequest \ System \ Default \ 1

              Then to test put one of your created namespaces like this [[%yournamespace.something]]. Don´t forget to clear chache
                • 16899
                • 284 Posts
                Quote from: robotpapier at Apr 15, 2014, 04:37 PM
                ok nevermind for the onHandleRequets, I think I got, just re-read the previous post smiley

                LOL!!!! Yes!!! All you need to know it´s there. Please let me know if you did it successfully!!! smiley
                  • 47243
                  • 30 Posts
                  ok! thanks again!
                  yes it's working.
                  But why is it a problem to load the lexicon context like 3 times in the same page?
                  because if I don't use my namepace as a prefix for the key name, it is possible that this key name already exist in other namespace.
                  so I tested with a key that already exist and it appears thaht the priority is to the core namespace.
                  So for now I just left the load of lexicon that repaet itself 3 times in 3 different chunk on the same page.

                  and also why is "
                  if($modx->context->get('key') == 'mgr' || $modx->event->name != 'OnHandleRequest') { return ''; }
                  " necessary can't we just put
                  $modx->lexicon->load('myNameSpace:default');
                  in the plugin?

                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Because you don't want this activated for the Manager, or for anything else besides processing HTTP page requests. You might be able to get away with not making such a check, but then again it just might cause some unexpected results where you least expect it.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 47243
                      • 30 Posts
                      ok, thanks for the tips!