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

    Is there any way to translate the category names in the manager?

    I investigated to do it with the help of a plugin using the 'OnResourceTVFormRender' to translate the category names of the TVs of a resource with no success...

    <?php
    /**
    		set for event: OnResourceTVFormRender:
    			'categories' => &$finalCategories,
                'template' => $templateId,
                'resource' => $this->resource->get('id'),
                'tvCounts' => &$this->tvCounts,
                'hidden' => &$hidden,
    
    			
    **/
    $eventName = $modx->event->name;
    switch($eventName) {
        case 'OnResourceTVFormRender':
                    $lexiconname = empty($lexiconname)?'website':$lexiconname;
    
                    $modx->getService('lexicon','modLexicon');
                    $modx->lexicon->load($lexiconname.':default');
    
                    foreach($categories as $id=>$aCategory)
                    {
                            //translate category name
                            $aCategoryName = $modx->lexicon($aCategory['category']);
    
    		/** the following line does not work :-(
    		  the new values in $categories seams correct but when coming back to manager/controllers/default/resource/resource.class.php,
    		  $finalCategories is not updated... 
    		**/
                            $categories[$id]['category'] = $aCategoryName;
                    }
            break;
    }
    return;



    Thanks for any help!
      • 3749
      • 24,544 Posts
      Try this:

      $aCategoryName = $modx->lexicon($aCategory);


      In your foreach loop, I $aCategoryName will contain the category name.

      The OnResourceTVFormRender event accepts a return value, which IIRC in your plugin would have to be set in $modx->event->_output rather than a return statement, but it's hard to see how it would work since it looks like the return value must be an array and is used to set Smarty placeholders.




        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
        • 33996
        • 20 Posts
        Hi Bob,
        Actually, the translation is ok and the values are correctly set in the $categories array as expected.

        As the $categories was a pointer, I thought that updating the array would be enough to the core (manager/controllers/default/resource/resource.class.php) to go ahead with my new values...

        Anyway, your answer sounds to say that there is no "standard" procedure to translate the category names in the manager :-s
          • 3749
          • 24,544 Posts
          There may be a "standard" procedure, but clearly I don't know what it is. wink

          I have a feeling that there's a way to make the categories show up in the correct language using $modx->event->_output in the plugin, but it would take some serious trial-and-error work (for me anyway) to get it right.

          It's also remotely possible that MODX would accept language tags ( [[%language_key]] ) as category names and translate them for you in the Manager using the current manager_language setting if you put the lexicon keys and values (in Manage -> Lexicons) in the core namespace under a topic that's loaded for the current manager page. I've never tried it.
            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
            • 33996
            • 20 Posts
            I'll test&try these 2 leads... and will give you the feedbacks!
            Thanks