2

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:

SHOUT_TIME="day"
SHOUT_AGO="ago"

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?

6

Add further abstraction.

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

English language

COM_MYCOMPONENT_DATETIME_AGO="%1$s %2$s %3$s"

German language

COM_MYCOMPONENT_DATETIME_AGO="%3$s %1$s %2$s"

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.