-
-
Save alaminfirdows/3233c42a8105d0c570390911ed3f4ecb to your computer and use it in GitHub Desktop.
<?php | |
class Bengali | |
{ | |
// Numbers | |
public static $bn_numbers = ["১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯", "০"]; | |
public static $en_numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]; | |
// Months | |
public static $en_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | |
public static $en_short_months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | |
public static $bn_months = ['জানুয়ারী', 'ফেব্রুয়ারী', 'মার্চ', 'এপ্রিল', 'মে', 'জুন', 'জুলাই', 'অগাস্ট', 'সেপ্টেম্বর', 'অক্টোবর', 'নভেম্বর', 'ডিসেম্বর']; | |
// Days | |
public static $en_days = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; | |
public static $en_short_days = ['Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri']; | |
public static $bn_short_days = ['শনি', 'রবি', 'সোম', 'মঙ্গল', 'বুধ', 'বৃহঃ', 'শুক্র']; | |
public static $bn_days = ['শনিবার', 'রবিবার', 'সোমবার', 'মঙ্গলবার', 'বুধবার', 'বৃহস্পতিবার', 'শুক্রবার']; | |
// Times | |
public static $en_times = array('am', 'pm'); | |
public static $en_times_uppercase = array('AM', 'PM'); | |
public static $bn_times = array('পূর্বাহ্ন', 'অপরাহ্ন'); | |
// Method - English to Bengali Number | |
public static function bn_number($number) | |
{ | |
return str_replace(self::$en_numbers, self::$bn_numbers, $number); | |
} | |
// Method - Bengali to English Number | |
public static function en_number($number) | |
{ | |
return str_replace(self::$bn_numbers, self::$en_numbers, $number); | |
} | |
// Method - English to Bengali Date | |
public static function bn_date($date) | |
{ | |
// Convert Numbers | |
$date = str_replace(self::$en_numbers, self::$bn_numbers, $date); | |
// Convert Months | |
$date = str_replace(self::$en_months, self::$bn_months, $date); | |
$date = str_replace(self::$en_short_months, self::$bn_months, $date); | |
// Convert Days | |
$date = str_replace(self::$en_days, self::$bn_days, $date); | |
$date = str_replace(self::$en_short_days, self::$bn_short_days, $date); | |
$date = str_replace(self::$en_days, self::$bn_days, $date); | |
return $date; | |
} | |
// Method - English to Bengali Time | |
public static function bn_time($time) | |
{ | |
// Convert Numbers | |
$time = str_replace(self::$en_numbers, self::$bn_numbers, $time); | |
// Convert Time | |
$time = str_replace(self::$en_times, self::$bn_times, $time); | |
$time = str_replace(self::$en_times_uppercase, self::$bn_times, $time); | |
return $time; | |
} | |
// Method - English to Bengali Date Time | |
public static function bn_date_time($date_time) | |
{ | |
// Convert Numbers | |
$date_time = str_replace(self::$en_numbers, self::$bn_numbers, $date_time); | |
// Convert Months | |
$date_time = str_replace(self::$en_months, self::$bn_months, $date_time); | |
$date_time = str_replace(self::$en_short_months, self::$bn_months, $date_time); | |
// Convert Days | |
$date_time = str_replace(self::$en_days, self::$bn_days, $date_time); | |
$date_time = str_replace(self::$en_short_days, self::$bn_short_days, $date_time); | |
$date_time = str_replace(self::$en_days, self::$bn_days, $date_time); | |
// Convert Time | |
$date_time = str_replace(self::$en_times, self::$bn_times, $date_time); | |
$date_time = str_replace(self::$en_times_uppercase, self::$bn_times, $date_time); | |
return $date_time; | |
} | |
} |
ভাই বাংলা ক্যালেন্ডার এ কনভার্ট করা যাবে?
You can translate any dates by using this helper.
// English to Bengali Number
echo Bengali::bn_number("1234"); // ১২৩৪
// Bengali to English Number
echo Bengali::en_number("১২৩৪"); // 1234
// English to Bengali Date
echo Bengali::bn_date("10 January 2025"); // ১০ জানুয়ারি ২০২৫
// English to Bengali Time
echo Bengali::bn_time("10:30 AM"); // ১০:৩০ পূর্বাহ্ন
// English to Bengali Date-Time
echo Bengali::bn_date_time("10 January 2025, 10:30 AM"); // ১০ জানুয়ারী ২০২৫, ১০:৩০ পূর্বাহ্ন
eta kivabe laravel e use korbo ?
Create a controller and you can call it directly from UI like this.
I have created a controller named BntextController
and pasted the code inside the class. BntextController
Calling it directly from the UI
{{ \App\Http\Controllers\BntextController::bn_date_time(date('d M Y h:m a', strtotime($invoice->created_at))) }}
Output is: ২৯ জুন ২০২৪ ০৮:০৬ পূর্বাহ্ন
Some issues may occur due to text errors inside the code I have fixed in my code.
my forked gist with fixes https://gist.github.com/abidtkg/d2d114a57e0b53a8724c593a68380d2c
eta kivabe laravel e use korbo ?