1

I need to translate post publish dates from English to Arabic.

I uploaded the po file from this link, using WPML string translation: http://wpcentral.io/internationalization/ar/

The .po file has translations for months, but not years and dates.

I want a date like 22 January 2015 to appear as ٢٢ يناير ٢٠١٥, but I can only get it to show up as 22 يناير 2015

What am I missing out?

1
  • Switch to one of the default themes, turn off all plugins and try again. If the problem stays, please report back here.
    – kaiser
    Feb 23, 2015 at 19:41

1 Answer 1

1

Found it. Anyone with a similar problem can add this code to their site plugin or theme functions.php

function convert_numbers_to_arabic( $string ) {
    $arabic_numbers = array('۰', '۱', '۲', '۳', '٤', '۵', '٦', '۷', '۸', '۹', '.');
    $english_numbers = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.');
    return str_replace($english_numbers, $arabic_numbers, $string);
}

add_filter( 'get_the_time', 'wpse_convert_arabic_time' );
add_filter( 'get_the_date', 'wpse_convert_arabic_time' );

function wpse_convert_arabic_time( $the_time ) {
    if ( get_bloginfo( 'language' ) == 'ar' ) { 
        $the_time = convert_numbers_to_arabic( $the_time );
    }
    return $the_time;
}
0

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.