I have an extension that displays the time a shout was posted, for example:

1 day ago

This string is generated in my helper like so:

$num . ' ' . JText::_('SHOUT_TIME') . ' ' . JText::_('SHOUT_AGO')

The language constants are as follows:


Now, in English this is perfectly fine, however in let's say, German, ago translates into vor.

The result of this would be 1 tag vor, however it should be vor 1 tag.

Bare in mind that SHOUT_TIME, could be one of the following:

  • second
  • minute
  • hour
  • day
  • month
  • year

so this needs to be a separate language string.

So how can I switch the string around to cater for other language without using conditional statements in the helper?


Add further abstraction.

JText::sprintf('COM_MYCOMPONENT_DATETIME_AGO', $num, JText::_('SHOUT_TIME'), JText::_('SHOUT_AGO'));

English language


German language


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.