Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
in Q2A Core by

Hello, I want to add a string in the tags page, but I want this string to be translated into other languages. I want to write questions instead of x. 

How do I change the ranking_count function?

public function ranking_count($item, $class)
   $this->ranking_cell($item['count'] . ' ×', $class . '-count');

I know that the field ((×)) It should be changed to ((questions)), but I don't know how it can be translated 

Q2A version: 1.8

1 Answer

+1 vote
selected by
Best answer

The right way to do this is write a plugin which includes a layer that overrides that method and includes its local translation file.

If this gets too complicated, then there is always the quick and dirty:

1. In each of the translation directories create a qa-lang-zzz.php file like this (change zzz and aaa to whatever you want, but keep the changes consistent in later steps):

return array(
    'aaa' => ' question(s) ',

2. Extend your theme and include this function in it:

public function ranking_count($item, $class) {
    $separator = qa_lang_html('zzz/aaa');
    $this->ranking_cell($item['count'] . $separator, $class . '-count');

And that's it. You can check the $item['count'] value and change the string based on whether the values matches 1 or not. That way you can decide to use the translated singular or the translated plural.

Great...thanks a lot