Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
9.1k views
in Q2A Core by
edited by

I'm using Q2A in Persian. Every thing is Ok. The only problem is that I can't display the questions' votes, answers, and views counter in Persian fonts (they're now in English) even though I use              font-family: <My Persian Font>; in the .qa-netvote-count-data, .qa-a-count-data, and .qa-view-count-data. 

How to display the questions' votes, answers, and views counter in Persian fonts?

 

Update: By applying the solution given below by sama55, I get this output whish is not correct.

2 Answers

+4 votes
by
selected by
 
Best answer

Originally it would be better to deal with server-side. This "server-side" is qa-theme/(Your theme)/qa-theme.php. However, I recommend that you cope by Javascript for reasons below.

  • I guess that you are not familiar with PHP
  • Probably, you will hope to convert other numbers (e.g. user points) of answers, comments, views. In that case, it will be difficult to find location (function) to be corrected in the PHP source.

This is not good, but I introduce simple way.

Reference:
http://stackoverflow.com/questions/15247405/how-to-replace-numbers-in-body-to-persian-numbers

  1. Convert encode qa-content/qa-page.js from ascii to UTF-8
  2. Add codes below at the last of qa-content/qa-page.js
  3. Clear cache of your browser
$(document).ready(function(){
  persian={0:'۰',1:'۱',2:'۲',3:'۳',4:'۴',5:'۵',6:'۶',7:'۷',8:'۸',9:'۹'};
  function traverse(el){
    if(el.nodeType==3){
      var list=el.data.match(/[0-9]/g);
      if(list!=null && list.length!=0){
        for(var i=0;i<list.length;i++)
          el.data=el.data.replace(list[i],persian[list[i]]);
      }
    }
    for(var i=0;i<el.childNodes.length;i++){
      traverse(el.childNodes[i]);
    }
  }
  $('.qa-netvote-count-data, .qa-a-count-data, .qa-view-count-data').each(function(){
    traverse($(this).context);
  });
});
If you hope to convert other value, add class name of that element. For example of activity widget, add ", .qa-activity-count-data" in upper js code.
by
Yes, I did exactly what you said.
by
In my environment, I got correctly result. Did you edit javascript file with notepad of windows? If so, cause may be BOM (Byte Order Mark). Try same edit operation with Nopepad++. And save as "UTF-8 without BOM".
http://notepad-plus-plus.org/
https://www.phpbb.com/community/viewtopic.php?f=66&t=1584655
by
Wow! You are right. The notepad causes the problem. Notepad++ fixed the problem. Thank you very much.
BTW, I'll accept your answer.
by
nice solution sama .. really helpfull .
+2 votes
by
You can't convert numbers to persian using fonts. that's impossible. you need something like this

http://usablica.github.io/persian.js/

 

use   $post[answers_raw]  to   get raw integer of  count of answers in qa-theme-base  in line 1583

barodar)))
by
Thanks for your reply, but could you please explain this method in more details?
I'm completely new in programming.
by
Unfortunately I'm not good at JS, I thought you know it. I think it's possible to convert numbers using php as well. I found this easy code:

function convert($post[answers_raw]) {
        $num = range(0, 9);
        $persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
    return str_replace( $num, $persian, $post[answers_raw]);
}   

You need to change farsi numbers with unicode :) Place it inside that function
by
Where should I place this code in my installation directory? What about Persian.js?
by
moved by

Can anyone else please explain the method described by @Sardor in more details?
I'm completely new in programming.

by
you can place the code inside a_count  function  in 1580s lines
...