Translate or convert WordPress date/time/comment number to Bangla digit

69 thoughts on “Translate or convert WordPress date/time/comment number to Bangla digit”

  1. Nice 🙂

    In my opinion its pretty ridiculous in localization. When, I faced it first time I was like w**! for localized date it returns 1 জানুয়ারী, 2010. Isn’t it ridiculous 😐 ??

  2. Great tip. A question that might help wpml users like me: if you serve your site in many languages, is there a way to replace digits depending on the chosen language for the site?

    Thanks for your work and publication!

  3. ধন্যবাদ ভাই, এটি আমার নতুন ওয়ার্ডপ্রেস প্রোজেক্টের জন্য খুবই কাজে লেগেছে।

  4. Hi brother, Thanks for this nice tips. I use it and working great but I have one problem. I hope you can give me suggestion what to do with it. I want to show the current date in the header in bangla. But I cant do that. I call it in my themes with but it shows enlish time. Is there anyway to show the date in Bengali? It will be great help for me. Thanks again for your nice tips.

    1. You want to Bangla date like “১৩ শ্রাবণ, ১৪১৭” or “১৩ জানুয়ারী ২০১০”. Which one is that?

      If it’s the first one, you may use my “Bangla Date” php class, you will find it here (my blog). But if it’s the second one, you have to use Bangla language pack for wordpress.

      1. আমিও 1 জানুয়ারী 2012 থেকে মুক্তি চাচ্ছি। কিন্তু বাংলা ল্যাঙ্গুয়েজ প্যাক ইউজ করে এটা ঠিক হয় না। ইভেন তারিখের জন্য আপনার বানানো ফানশনটা ইউজ করেছি…

        কিন্তু আমার আর্কাইভে ‘জানুয়ারী 2012’ এভাবে দেখায়…
        আর পেজিনেশনে ” এভাবে দেখাচ্ছে…এটার সমাধান কি ভাইয়া?

  5. সুন্দর পোস্ট। মাস বাদ গেল কেন? এভাবে লিখুন ফাংশনটা,তাহলে আরো ভালো হয়:
    function make_bangla_number($str)
    {
    $engNumber = array(1,2,3,4,5,6,7,8,9,0);
    $bangNumber = array(১,২,৩,৪,৫,৬,৭,৮,৯,০);
    $engMonth = array("January","February","March","April","May","Jun","July","August","September","October","November","December");
    $bangMonth = array("জানুয়ারি","ফেব্রুয়ারি","মার্চ","এপ্রিল","মে","জুন","জুলাই","আগস্ট","সেপ্টেম্বর","অক্টোবর","নভেম্বর","ডিসেম্বর");
    $converted = str_replace($engNumber, $bangNumber, $str);
    $converted = str_replace($engMonth, $bangMonth, $converted);

    return $converted;
    }

    1. আমরা যেহেতু লোকালাইজেশন করছি, ওয়ার্ডপ্রেসের ল্যাঙ্গুয়েজ ফাইলই মাসের নাম বাংলা করে ফেলবে। কিন্তু ডিজিট গুলা কোন সময় বাংলা হয় না। সে জন্যেই এই হ্যাক 🙂

      1. এইটা শুধু PHP দিয়েই করা যায়। strftime এই ফাংশানটির বিস্তারিত দেখুন।
        ওয়ার্ডপ্রেসেরও এইটা দিয়েই করার কথা 😕

      2. বুঝতে পেরেছি। আমি ব্লগে ল্যাংগুয়েজ প্যাক ব্যবহার না করে নিজেই অনুবাদ করে
        নিয়েছি তাই ওটা যোগ করতে হয়েছে।

        1. এইটা ট্রাই করে দেখতে পারেন, উইন্ডোজে কাজ করার সম্ভাবনা নেই 🙂 তবে লিনাক্সে ঠিক ই কাজ করবে-

          setlocale(LC_ALL, 'bn_BD.utf8');
          echo strftime("%B");

  6. আপনার পোস্টটি আমার খুব ভাল লেগেছে। বাংলা তারিখের জন্য আমি আপনার স্ক্রিপ্টটি ব্যবহার করছি
    আমি ইংরেজি থেকে বাংলা সংখ্যা convert করার জন্য এই function টি বানিয়েছিলাম

    function _bnno($no)
    {

    $monthfull = array(
    “January”=>”জানুয়ারি”,
    “February”=>”ফেব্রুয়ারি”,
    “March”=>”মার্চ”,
    “April”=>”এপ্রিল”,
    “May”=>”মে”,
    “June”=>”জুন”,
    “July”=>”জুলাই”,
    “August”=>”আগস্ট”,
    “September”=>”সেপ্টেম্বর”,
    “October”=>”অক্টোবর”,
    “November”=>”নভেম্বর”,
    “December”=>”ডিসেম্বের”);

    $dayfull = array(
    “Saturday”=>”শনিবার”,
    “Sunday”=>”রবিবার”,
    “Monday”=>”সোমবার”,
    “Tuesday”=>”মঙ্গলবার”,
    “Wednesday”=>”বুধবার”,
    “Thursday”=>”বৃহস্পতিবার”,
    “Friday”=>”শুক্রবার”);

    $sonkha = array(‘০’,’১’,’২’,’৩’,’৪’,’৫’,’৬’,’৭’,’৮’,’৯’);
    $all = array_merge($monthfull,$sonkha,$dayfull);
    return strtr($no, $all);

    }

  7. PHP don’t support unicode literals or numerals. So, you should enclose all bengali digits with single or double quotes in the $bangNumber array.

    Also if any of the functions upon which the filter function will work produces html entities for unicode characters (for example » to output >>), this function will also change those which is un-acceptable.

    I’ve made an workaround to this issues using preg_replace_callback and here is the pastebin link –

    http://pastebin.com/EZki6KMc

    1. Bangla digits without quote works for me (LAMP). Don’t know about your condition and I didn’t faced any HTML entity related problems till now.

      1. Though PHP usually don’t complain for un-quoted literals with default settings (default value of error_reporting flag is E_ALL & ~E_NOTICE) its a good practice to develop using E_ALL only excluding to catch maximum errors as well as to optimize page execution time. Every time PHP encounters an un-quoted literal, it try to look up the global symbol table for constants, if it fails (as in this case) it automatically converts that to the corresponding string literal (১ becomes ‘১’ and so on…) and generates a run time NOTICE with message similar to:

        Notice: Use of undefined constant ১ – assumed ‘১’ in the_file_with_line_number

        If you never encounter such error during development, than you might not alter the default PHP settings for error_reporting directive and should read the recommended php.ini settings for development in

        http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

        And regarding the HTML entity related issue, if none of your plugin or theme alters the default output generated by WP for the filtered functions, you won’t encounter this issue. But it is always best to support exceptional boundary cases while you are publishing for people.

        Still, great work whatever you’ve done.

        1. Yeah, my error reporting was not printing notices. Turning it ON produces the notices you talked about. Thanks for the little info 😀

          And yes, may be in that case some other plugins were conflicting, thats why the entities showed their dirty faces 😛

          Thanks

  8. প্লাগিন এর number বা digit কিভাবে বাংলা করবো,আপনার টিউটোরিয়াল দিয়ে থিম এর ডিজিট বাংলা করতে পেরেছি কিন্তু আমি যে প্লাগিন গুলা ইউজ করি সেসব ও তো অনেক ইংলিশ নাম্বার শো করে যা দেখতে খুবই খারাপ লাগে।একই পেজ এ বাংলা এবং ইংরেজির এই সংমিশ্রন বিরক্তিকর।

    আপনি যদি এই ব্যাপারে কোন টিউটোরিয়াল লিখেন তাহলে খুবই উপকৃত হবো।
    ভালো থাকবেন।

    1. যদি সেই প্লাগিন গুলো কোন ফিল্টার সাপোর্ট করে, তাহলে উপরের পদ্ধতিতে ফিল্টার দিয়েই ডিজিট গুলা পরিবর্তন করা যাবে। কিন্তু ফিল্টার না থাকলে ম্যানুয়ালী করা ছাড়া উপায় নাই।

      1. আমিও এরকমই সমস্যায় পরেছি। আমার প্লাগইন কোন কোন ফিল্টার সাপোর্ট করে সেটা কিভাবে জানতে পারবো? আর ফিল্টার না থাকলে ম্যানুয়ালী কিভাবে করতে হবে সেটা যদি একটু জানাতেন তাহলে খুবই উপকৃত হতাম।

        1. অনেক সময় আমরা PHP তে তারিখ প্রিন্ট করি date() ফাংশন দিয়ে। এক্ষেত্রে প্লাগিনে যদি এভাবেই তারিখ সরাসরি প্রিন্ট করানো হয়, তাহলে সেটা ট্রান্সলেট করার উপযোগী হবে না। আবার ওয়ার্ডপ্রেসের একটা ট্রান্সলেটেবল date ফাংশন আছে date_i18n(), সেই প্লাগিনে যদি এটা ইউজ করা হয়, তাহলে টেক্সট ট্রান্সলেটের উপযোগী হবে।

  9. উত্তরের জন্য ধন্যবাদ।
    দেখি চেষ্টা করে কিছু করতে পারি কিনা।
    আবারো ধন্যবাদ আপনাকে।

  10. ভাইয়া,
    অনেক ধন্যবাদ। আপনার কোডটুকু কাজে লাগালাম। শুভ কামনা রইলো।

  11. খুবই সুন্দর এবং উপকারী একটা কাজ হয়েছে। আপনাকে অসংখ্য ধন্যবাদ তারেক হাসান। অনেক অনেক শুভকামনা। ঈশ্বর সহায় হোন।

  12. পোস্ট সংখ্যা জানার জন্য আমি একটি ভারিয়েবল ব্যাবহার করছি, $post_count , কিন্তু এটাকে কি করে বাংলা দেখাবো ??
    দয়া করে একটু সাহায্য করবেন।

    আমার পরো কোডঃ
    get_queried_object();
    $post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth->ID . "' AND post_type = 'post' AND post_status = 'publish'");
    echo "প্রকাশিত পোস্টঃ $post_count টি";
    ?>

  13. Thanks again for your great post.
    Anyways, I have a doubt that how could I translate the date and time of the Archive widget?
    Another one is the phrase “3 Thoughts on Post Title”; it doesn’t show in PoEdit at all because it’s plural form. I’ve try to customize setting of some tutorials in Poedit but no luck. Therefore, I use plugin and it appear to translate it well.
    Yet, how could I change the number “3” into my own string or my native numbers.
    Thanks!

    Jame

  14. আপনার কোডটা ব্যবহার করলে সপ্তাহের সাতদিনের নাম বাংলা হচ্ছে না। এক্ষেত্রে কি করবো?

    1. বাংলা ল্যাঙ্গুয়েজ প্যাক ব্যবহার করলেই তো হয়ে যাবার কথা

      1. প্লাগিন এবং বাংলা ল্যাংগুয়েজ প্যাক বাদে করতে চাচ্ছি বলেই আপনার কোড টা ব্যবহার করেছি। অনেক খানি কাজও হয়েছে কিন্তু একটি নতুন থিম এ বার ও দেখাচ্ছে হোম পেজ এ যা আমিও চাচ্ছিলাম।তখন দেখলাম তা ইংরেজি হয়ে রয়েছে আপনি যদি আমাকে বার বাংলা করার কোডটা দিতেন তাহলে অনেক উপকার হত

        1. OOP Approach এর মধ্যে translate_day ফাংশনে নিচের কোডটা বসিয়ে দিলেই হয়ে যাবার কথা
          [php]
          $bn_day = array( ‘শনিবার’, ‘রবিবার’, ‘সোমবার’, ‘মঙ্গলবার’, ‘বুধবার’, ‘বৃহস্পতিবার’, ‘শুক্রবার’ );
          $en_day = array( ‘Saturday’, ‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’ );
          $str = str_replace( $en_day, $bn_day, $str );
          [/php]

          1. কোথায় বসাবো ঠিক বুঝলাম না। আপনি যদি কোড টা বারের বাংলা টা সহ Pastebin এ দিয়ে দিতেন তাহলে খুবই উপকার হত

  15. আমার পোস্ট এর তারিখ এই ভাবে দেখাচ্ছে …
    ( এপ্রিল ১৬, ২০১৩ । ৪:১৩ পূর্বাহ্ন )

    আমি যদি এই সময় গুলোকে ভোর, সকাল, বিকাল, দুপুর, সন্ধ্যা, রাত, মধ্যরাত এ ভাগ করতে চাই, তাহলে কি করতে হবে?

    আপনার এই FUNCTION ব্যাবহার করে কি এই কাজটা করা যাবে??

    function translate_am( $str ) {
    $en = array( 'am', 'pm' );
    $bn = array( 'পূর্বাহ্ন', 'অপরাহ্ন' );

    $str = str_replace( $en, $bn, $str );

    return $str;
    }

    দয়া করে একটু সাহায্য করবেন কি?

    1. am, pm এর উপর নির্ভর করে কয়েকটা if/else ব্লকের মধ্যে ফেলে দিলেই হয়ে যাবে। চেষ্টা করুন, পারবেন 🙂

      1. আর একটু বুঝিয়ে বললে , উপকার হইত খুব। আমি নিজে ভালো প্রোগ্রামার নই… 😛

  16. ভাইয়া আমি WP-Postview প্লাগিন টা ব্যবহার করে আমার সাইট এ পোস্টভিউ দেখাচ্ছি। কিন্তু সংখ্যা গুলা বাংলা আসছে না। সব আসছে ইংরেজি তে। এইটা থেকে মুক্তি পাওয়ার উপায় কি?

  17. আমি আমার সাইটে এখন পর্যন্ত সকল সমস্যার সমাধান করে ফেলেছি। বাংলা নিয়ে আর চিন্তা নাই। তবে তারেক ভাইয়ের লেখাটা দারুন হেল্প করেছে, তাই কৃতজ্ঞতা স্বীকার করছি। আমার মনে হয় সকলেই পারবেন। কেউ যদি বুঝতে না পারেন তবে প্রশ্ন করবেন। ধন্যবাদ তারেক ভাই।

  18. এই ফাংশনটি ব্যাবহার করলে ডেসবোর্ডে কিছু ওয়ারনিং দেখাই

      1. এরকম ওয়ার্ণিং দেখায়।
        Warning: date() expects parameter 2 to be long, string given in /path/to/wordpress/wp-admin/includes/dashboard.php on line 709

  19. আপনার কোডগুলো থিমের কোথায় ব্যবহার করব, যেমন- হেডার, ফুটার, ফাংশান ইত্যাদি । এর জন্য কি কোন প্লাগিন ব্যবহার করে হবে নাকি।

    1. ফাংশন-এ যোগ করার পর কাজ হইছে । ধন্যবাদ।
      আমার আরেকটা সাহায্য লাগবে, তাহল আমি edit, admin, comment এই লেখাগুলোকে কিভাবে বাংলা করব

  20. Thank you for your post. I was looking for a similar solution to convert English numbers to Arabic numbers.

    You saved my time and efforts.

Leave a Reply to শিশির Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.