Support » Plugin: wp-jalali » WordPress Jalali Multilingual Support

  • Hi Dear Users
    I had a problem with multilingual support (Which is that Wp-Jalali does not support) and i figured it out and just wanted to let you guys know if you want to use it in other languages.

    There is a line of code in the file
    wp-content/plugins/wp-jalali/lib/date.php at line 475 :

    function gregorian_to_jalali($g_y, $g_m, $g_d) {
        static $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        static $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
        $gy = $g_y - 1600;
        $gm = $g_m - 1;
        $g_day_no = (365 * $gy + int_div($gy + 3, 4) - int_div($gy + 99, 100) + int_div($gy + 399, 400));
        for ($i = 0; $i < $gm; ++$i) {
          $g_day_no += $g_days_in_month[$i];
        }
        if ($gm > 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0)))
        # leap and after Feb
        $g_day_no ++;
        $g_day_no += $g_d - 1;
        $j_day_no = $g_day_no - 79;
        $j_np = int_div($j_day_no, 12053); # 12053 = (365 * 33 + 32 / 4)
        $j_day_no = $j_day_no % 12053;
        $jy = (979 + 33 * $j_np + 4 * int_div($j_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
        $j_day_no %= 1461;
        if ($j_day_no >= 366) {
          $jy += int_div($j_day_no - 1, 365);
          $j_day_no = ($j_day_no - 1) % 365;
        }
        for ($i = 0; ($i < 11 && $j_day_no >= $j_days_in_month[$i]); ++$i) {
          $j_day_no -= $j_days_in_month[$i];
        }
        return array($jy, $i + 1, $j_day_no + 1);
    }

    Just change it to :

    function gregorian_to_jalali($g_y, $g_m, $g_d) {
      if  (get_locale() == 'fa_IR') {
    
        static $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        static $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
        $gy = $g_y - 1600;
        $gm = $g_m - 1;
        $g_day_no = (365 * $gy + int_div($gy + 3, 4) - int_div($gy + 99, 100) + int_div($gy + 399, 400));
    
        for ($i = 0; $i < $gm; ++$i) {
          $g_day_no += $g_days_in_month[$i];
        }
    
        if ($gm > 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0)))
        # leap and after Feb
        $g_day_no ++;
        $g_day_no += $g_d - 1;
        $j_day_no = $g_day_no - 79;
        $j_np = int_div($j_day_no, 12053); # 12053 = (365 * 33 + 32 / 4)
        $j_day_no = $j_day_no % 12053;
        $jy = (979 + 33 * $j_np + 4 * int_div($j_day_no, 1461)); # 1461 = (365 * 4 + 4 / 4)
        $j_day_no %= 1461;
    
        if ($j_day_no >= 366) {
          $jy += int_div($j_day_no - 1, 365);
          $j_day_no = ($j_day_no - 1) % 365;
        }
    
        for ($i = 0; ($i < 11 && $j_day_no >= $j_days_in_month[$i]); ++$i) {
          $j_day_no -= $j_days_in_month[$i];
        }
    
        return array($jy, $i + 1, $j_day_no + 1);
      }else{
        return array($g_y, $g_m, $g_d);
      }
    }

    Then your problem is solved, Notice that you can use get_locale(); to get the current language of site.

    I am a professional web developer, Contact me if you need help
    email : info@porshad.net

    https://wordpress.org/plugins/wp-jalali/

  • The topic ‘WordPress Jalali Multilingual Support’ is closed to new replies.