Created
July 9, 2019 13:02
-
-
Save alaminfirdows/3233c42a8105d0c570390911ed3f4ecb to your computer and use it in GitHub Desktop.
Laravel Bangla Date, Time and Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tareqRahman5
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. BntextControllerCalling 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