2

I know at some point sprintf was a method of the JText class, but it doesn't seem to work in Joomla 4.0. I tried the following, not working:

$str = Text::sprintf('JFIELD_COLOR_ADVANCED_INPUT_PLACEHOLDER', 'JFIELD_COLOR_ADVANCED_FORMAT_RGB');

Here's what I have and it works

$placeholder = sprintf(Text::_('JFIELD_COLOR_ADVANCED_INPUT_PLACEHOLDER'), Text::_('JFIELD_COLOR_ADVANCED_FORMAT_RGB'));

I need to know if there is a replacement for the deprecated JText::sprintf() method in Joomla 4.0, or is my method basically the way to do it now?

Thanks

2

If you want to translate the variables, you need to do it before passing them to Text::sprintf():

Text::sprintf('JFIELD_COLOR_ADVANCED_INPUT_PLACEHOLDER', Text::_('JFIELD_COLOR_ADVANCED_FORMAT_RGB'));

This hasn't changed since J3 and Joomla\CMS\Language\Text::sprintf() is not deprecated in J4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.