XF 2.3 Phrase Rendering

Hello all,

I'm working on a simple add-on that intercepts phrases before they are rendered, performs some logic, and then returns the phrase. I've currently got the following code which works:

Code:
<?php

namespace AddonName\XF;

class Language extends XFCP_Language
{
    public function renderPhrase($name, array $params = [], $context = 'html', array $options = [])
    {
        // Call the parent method to get the original phrase
        $phrase = parent::renderPhrase($name, $params, $context, $options);

        // Apply custom logic to phrase
        $phrase = $this->doMyCustomLogic($phrase);

        // Return updated phrase
        return $phrase;
    }

I can see this being applied to certain phrases on my forum. However, it seems that any phrases that are referenced in templates using {{ phrase('phrase_name') }} don't get updated. For example, all phrases in the Admin Panel get updated. Phrases used in widgets seem to be updated, as well as my navigation bar entries.

Is there a different method that is used in XenForo for rendering these sorts of phrases?
 
Last edited:
Most phrases are baked into the templates during compilation (see \XF\Template\Compiler\Func\Phrase). You can't hook template compilation but you might be able to hook the underlying \XF\Language::getPhraseText method instead, depending on what you're trying to do. Just note that your code would run once during compilation and not during render.
 
Back
Top Bottom