dotProject 行事曆的星期亂碼簡易解決方案
10 月.20, 2005 in dotProject, PHP
造成亂碼的原因是語系轉換的問題程式中是以取得星期幾的字串後取前三個英文字來轉換,所以判定的方式就不相容於中文的格式,因此造成顯示亂碼。所以要將此部份的顯示改成運用系統內的語系檔轉換來處理。
經過一陣程式碼的查訪後,歸納出以下兩大處理部份
1. 中文化的部份在 common.inc 的星期短碼如 Sun, Mon, Tue… 要翻譯成 日, ㄧ, 二…
2. 程式至少要修改的兩個部分:
修改 dotProject_INSTALL_PATH/modules/calendar/calendar.class.php 檔案的 function _drawDays()
1 2 3 4 5 6 7 8 9 | /** * CMonthCalendar::_drawDays() * * { Description } * * @return string Returns table a row with the day names */ function _drawDays() { global $locale_char_set, $AppUI; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $bow = Date_Calc::beginOfWeek( null,null,null,null,LOCALE_FIRST_DAY ); $y = substr( $bow, 0, 4 ); $m = substr( $bow, 4, 2 ); $d = substr( $bow, 6, 2 ); $wk = Date_Calc::getCalendarWeek( $d, $m, $y, "%a", LOCALE_FIRST_DAY ); $s = $this->showWeek ? "\n\t\t <th></th> <th width=""14%""></th> <th width=""14%""></th> </tr> $s\n "; } |
修改 dotProject_INSTALL_PATH/lib/PEAR/Date/Calc.php 檔案的 function getWeekDays()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Returns an array of week days * * Used to take advantage of the setlocale function to * return language specific week days * XXX cache values to some global array to avoid preformace hits when called more than once. * * @returns array An array of week day names */ function getWeekDays() { $sLocale = setlocale(LC_TIME, 0); // 加入此行 setlocale(LC_TIME, 'en_US'); // 加入此行 |
1 2 3 4 5 6 | for($i=0;$i<7;$i++){ $weekdays[$i] = strftime('%A', mktime(0, 0, 0, 1, $i, 2001)); } setlocale(LC_TIME, $sLocale); // 加入此行 return($weekdays); } |
環境說明
1. 作業系統:Linux FC3
2. 系統版本:dotProject 2.0.1
3. 使用編碼:UTF-8
4. 中文化方式:用英文版為基礎使用系統的語系編輯功能手動輸入
Tags: dotProject
Leave a Reply