Support » Plugin: Popular Widget » [Plugin: Popular Widget] 4 digit numbers have space not comma every third digit

  • Resolved Jon Scaife

    (@jonscaife)


    When displaying counts above 1,000 the counts are displayed with a space every 3 digits rather than a comma. So 1 million would be shown as “1 000 000” rather than “1,000,000”. It would be nicer to have the correct format used, and this would also prevent the number from line-breaking which makes it confusing to read. I’ve fixed this by making a single tweak to include.php as below…

    On line 241
    replace: $output .= '<span class="pop-count">('.preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/"," ",$post->views).')</span>';
    with: $output .= '<span class="pop-count">('.preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/",",",$post->views).')</span>';

    Cheers

    http://wordpress.org/extend/plugins/popular-widget/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Hax

    (@hax)

    will do, thanks for the feedback

    Actually, whether it should be a space, comma or dot is an internationalization issue and should depend on the chosen language of the installation.

    It’d be best to use the WP proprietary number_format_i18n( $number, $decimals = 0 ) function to get this right for every language in one go 😉

    So, the code would then become:
    On line 241
    replace: $output .= '<span class="pop-count">('.preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/"," ",$post->views).')</span>';
    with: $output .= '<span class="pop-count">('.number_format_i18n( $post->views, 0 ).')</span>';

    Hope this helps!

    Smile,
    Juliette

    Agreed Juliette – but I found making a single character change was a lot simpler than figuring out internationalisation.. Thank you for doing the leg work (or just having the knowledge) to do it properly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Popular Widget] 4 digit numbers have space not comma every third digit’ is closed to new replies.