2012-12-07, 09:22 PM
How to translate dates from English to whatever you want globally into your Forum
So here it is, a step-by-step tutorial on how to globally translate dates upon your Forum. I've searched for a similar tutorial but I didn't find it, if present feel free to delete this one.
Do you own a Forum and you're perhaps German, Italian or something else, and you want to fully translate dates? This tutorial is meant for you.
A little introduction
So, why dates are not translated by default? Because MyBB makes use of PHP date() function to generate dates and times and this function doesn't take care of user location, what setlocale() function actually does. MyBB won't support setlocale() as far as I know due to the massive amount of core changes this would require, but since the software uses its own custom date() function, we are able to edit this introducing a search and replace system which will find the English dates and replace them with our custom ones.
Let's start!
1. Download and install Patches plugin by frostschutz
If you haven't installed it yet, I highly recommend using this awesome plugin which let you make little core changes within the ACP itself, grouping them so you have full control over them in case of future MyBB updates.
Download Patches
2. Add some lines of code to inc/functions.php file
Within Patches plugin, set every field as following:
Filename: inc/functions.php
Title: Date translation
Description: Translate dates globally in the Forum with custom ones declared in global.lang.php file.
Search:
return $date;
Add before:
// Set up an array of default date()-generated date names and replace them with our custom ones!
$replace_array = array (
"January" => $lang->month_1,
"February" => $lang->month_2,
"March" => $lang->month_3,
"April" => $lang->month_4,
"May" => $lang->month_5,
"June" => $lang->month_6,
"July" => $lang->month_7,
"August" => $lang->month_8,
"September" => $lang->month_9,
"October" => $lang->month_10,
"November" => $lang->month_11,
"December" => $lang->month_12,
"Jan" => $lang->short_month_1,
"Feb" => $lang->short_month_2,
"Mar" => $lang->short_month_3,
"Apr" => $lang->short_month_4,
"May" => $lang->short_month_5,
"Jun" => $lang->short_month_6,
"Jul" => $lang->short_month_7,
"Aug" => $lang->short_month_8,
"Sep" => $lang->short_month_9,
"Oct" => $lang->short_month_10,
"Nov" => $lang->short_month_11,
"Dec" => $lang->short_month_12,
"Sunday" => $lang->sunday,
"Monday" => $lang->monday,
"Tuesday" => $lang->tuesday,
"Wednesday" => $lang->wednesday,
"Thursday" => $lang->thursday,
"Friday" => $lang->friday,
"Saturday" => $lang->saturday,
);
foreach ( $replace_array as $key => $val )
{
$date = str_replace ( $key, $val, $date );
}
Replace: no
3. Add the language variables to global.lang.php file
Now that the function has been edited, you have to edit inc/languages/[yourlanguage]/global.lang.php file. You can do this with Patches, again, but I recommend editing it directly just to avoid filling too much Patches list. Language files usually doesn't need to be updated, but feel free to use Patches if you want.
Open the file and add anywhere you want:
$l['month_1'] = "January";
$l['month_2'] = "February";
$l['month_3'] = "March";
$l['month_4'] = "April";
$l['month_5'] = "May";
$l['month_6'] = "June";
$l['month_7'] = "July";
$l['month_8'] = "August";
$l['month_9'] = "September";
$l['month_10'] = "October";
$l['month_11'] = "November";
$l['month_12'] = "December";
$l['short_month_1'] = "Jan";
$l['short_month_2'] = "Feb";
$l['short_month_3'] = "Mar";
$l['short_month_4'] = "Apr";
$l['short_month_5'] = "May";
$l['short_month_6'] = "Jun";
$l['short_month_7'] = "Jul";
$l['short_month_8'] = "Aug";
$l['short_month_9'] = "Sep";
$l['short_month_10'] = "Oct";
$l['short_month_11'] = "Nov";
$l['short_month_12'] = "Dec";
$l['sunday'] = "Sunday";
$l['monday'] = "Monday";
$l['tuesday'] = "Tuesday";
$l['wednesday'] = "Wednesday";
$l['thursday'] = "Thursday";
$l['friday'] = "Friday";
$l['saturday'] = "Saturday";
$l['short_monday'] = "L";
$l['short_tuesday'] = "M";
$l['short_wednesday'] = "M";
$l['short_thursday'] = "G";
$l['short_friday'] = "V";
$l['short_saturday'] = "S";
$l['short_sunday'] = "D";
Edit them accordingly to the language your using or editing the file for.
Reupload the file on your server and enjoy your dates translated into your desired language.