1

I'm using the Fivestar module on different areas of the site. It displays "x votes" below the rating widget.

On some areas on the site it would like to change "votes" to "reviews". How could I do that?

1 Answer 1

1

The 'votes' text seems to be hard-coded into the theme_fivestar_summary() function (around line 264 of 'includes/fivestar.theme.inc'). It is run through format_plural() (so will eventually make itself available to string overrides), but I don't know of a way of defining complex conditions/contexts for string overrides.

The only (easy) way I can see to solve this is to re-implement that theme function in your own theme, copying the full function code from theme_fivestar_summary() to MYTHEME_fivestar_summary(), and introducing a contextual condition to alter the specific text that you want to change.

You'd be basically looking at changing these lines:

if (isset($votes) && !(isset($user_rating) || isset($average_rating))) {
  $output .= ' <span class="total-votes">'. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .'</span>';
  $div_class = 'count';
}
elseif (isset($votes)) {
  $output .= ' <span class="total-votes">('. format_plural($votes, '<span>@count</span> vote', '<span>@count</span> votes') .')</span>';
}

to:

$context = MYTHEME_get_fivestar_context();
if ($context == 'something') {
  $metric = 'review';
}
else if ($context == 'something_else') {
  $metric = 'vote';
}

if (isset($votes) && !(isset($user_rating) || isset($average_rating))) {
  $output .= ' <span class="total-votes">'. format_plural($votes, '<span>@count</span> ' . $metric, '<span>@count</span> ' . $metric . 's') .'</span>';
  $div_class = 'count';
}
elseif (isset($votes)) {
  $output .= ' <span class="total-votes">('. format_plural($votes, '<span>@count</span> ' . $metric, '<span>@count</span> ' . $metric . 's') .')</span>';
}

It's not particularly pretty, but I think it's about the most efficient way to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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