From c226b843d5a2779612ee81706e478e7d61bcf850 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Mon, 15 Oct 2012 22:52:34 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/DashboardController.php | 48 ++++++------- app/controllers/ProblemController.php | 2 +- app/controllers/RecordController.php | 2 +- app/controllers/ReportController.php | 24 +++---- app/controllers/SubmitController.php | 4 +- app/controllers/UserController.php | 36 +++++----- app/models/User.php | 4 +- app/translate.php | 90 +++++++++++++++++++++++++ app/views/layout/header.php | 6 +- 9 files changed, 153 insertions(+), 63 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 6c587b7..be8d266 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -4,7 +4,7 @@ class DashboardController extends ApplicationController public function index() { if (!User::can('manage-site')) { - fMessaging::create('error', 'You are not allowed to view the dashboard.'); + fMessaging::create('error', T('You are not allowed to view the dashboard.')); fURL::redirect(Util::getReferer()); } @@ -100,25 +100,25 @@ private function showProblem($id, $ignore_git=FALSE) $ini_content = str_replace(': ', ' = ', $properties_content); $ini = parse_ini_string($ini_content); if (!array_key_exists('title', $ini) or empty($ini['title'])) { - throw new fValidationException('Problem title is not specified in problem.conf'); + throw new fValidationException(T('Problem title is not specified in problem.conf')); } if (!array_key_exists('author', $ini)) { - throw new fValidationException('Problem author is not specified in problem.conf'); + throw new fValidationException(T('Problem author is not specified in problem.conf')); } if (!array_key_exists('case_count', $ini) or empty($ini['case_count'])) { - throw new fValidationException('Problem case count is not specified in problem.conf'); + throw new fValidationException(T('Problem case count is not specified in problem.conf')); } if (!array_key_exists('case_score', $ini) or empty($ini['case_score'])) { - throw new fValidationException('Problem case score is not specified in problem.conf'); + throw new fValidationException(T('Problem case score is not specified in problem.conf')); } if (!array_key_exists('time_limit', $ini) or empty($ini['time_limit'])) { - throw new fValidationException('Problem time limit is not specified in problem.conf'); + throw new fValidationException(T('Problem time limit is not specified in problem.conf')); } if (!array_key_exists('memory_limit', $ini) or empty($ini['memory_limit'])) { - throw new fValidationException('Problem memory limit is not specified in problem.conf'); + throw new fValidationException(T('Problem memory limit is not specified in problem.conf')); } if (!array_key_exists('secret_before', $ini) or empty($ini['secret_before'])) { - throw new fValidationException('Problem secret-before time is not specified in problem.conf'); + throw new fValidationException(T('Problem secret-before time is not specified in problem.conf')); } if (empty($ini['author'])) { @@ -198,7 +198,7 @@ public function manageProblem($id, $action) { try { if (!User::can('manage-site')) { - throw new fAuthorizationException('You are not allowed to manage problems.'); + throw new fAuthorizationException(T('You are not allowed to manage problems.')); } if ($action == 'Show') { $this->showProblem($id); @@ -211,7 +211,7 @@ public function manageProblem($id, $action) fMessaging::create('success', "Problem {$id} refreshed successfully."); } else if ($action == 'Refresh All' and User::can('refresh-all')) { $this->refreshAllProblems(); - fMessaging::create('success', 'All problems refreshed successfully.'); + fMessaging::create('success', T('All problems refreshed successfully.')); } } catch (fException $e) { fMessaging::create('error', $e->getMessage()); @@ -223,7 +223,7 @@ public function rejudge($id) { try { if (!User::can('rejudge-record')) { - throw new fAuthorizationException('You are not allowed to rejudge records.'); + throw new fAuthorizationException(T('You are not allowed to rejudge records.')); } $old_record = new Record($id); $new_record = new Record(); @@ -247,10 +247,10 @@ public function manjudge($id, $score) { try { if (!User::can('rejudge-record')) { - throw new fAuthorizationException('You are not allowed to rejudge records.'); + throw new fAuthorizationException(T('You are not allowed to rejudge records.')); } if ($score < 0) { - throw new fValidationException('Score cannot be negative.'); + throw new fValidationException(T('Score cannot be negative.')); } $record = new Record($id); $record->manjudge($score); @@ -266,7 +266,7 @@ public function createReport() { try { if (!User::can('create-report')) { - throw new fAuthorizationException('You are not allowed to create reports.'); + throw new fAuthorizationException(T('You are not allowed to create reports.')); } $report = new Report(); $report->setVisible(fRequest::get('visible', 'integer')); @@ -276,7 +276,7 @@ public function createReport() $report->setStartDatetime(fRequest::get('start_time', 'timestamp')); $report->setEndDatetime(fRequest::get('end_time', 'timestamp')); $report->store(); - fMessaging::create('success', 'Report created successfully.'); + fMessaging::create('success', T('Report created successfully.')); } catch (fException $e) { fMessaging::create('error', $e->getMessage()); } @@ -293,7 +293,7 @@ public function manageReport($id, $action) $report->store(); fMessaging::create('success', "Report {$id} showed successfully."); } else { - throw new fAuthorizationException('You are not allowed to show this report.'); + throw new fAuthorizationException(T('You are not allowed to show this report.')); } } else if ($action == 'Hide') { if (User::can('view-any-report')) { @@ -301,14 +301,14 @@ public function manageReport($id, $action) $report->store(); fMessaging::create('success', "Report {$id} hidden successfully."); } else { - throw new fAuthorizationException('You are not allowed to hide this report.'); + throw new fAuthorizationException(T('You are not allowed to hide this report.')); } } else if ($action == 'Remove') { if (User::can('remove-report')) { $report->delete(); fMessaging::create('success', "Report {$id} removed successfully."); } else { - throw new fAuthorizationException('You are not allowed to remove this report.'); + throw new fAuthorizationException(T('You are not allowed to remove this report.')); } } } catch (fException $e) { @@ -328,17 +328,17 @@ public function managePermission($action) $permission->setUserName($user_name); $permission->setPermissionName($permission_name); $permission->store(); - fMessaging::create('success', 'Permission added successfully.'); + fMessaging::create('success', T('Permission added successfully.')); } else { - throw new fAuthorizationException('You are not allowed to add permissions.'); + throw new fAuthorizationException(T('You are not allowed to add permissions.')); } } else if ($action == 'Remove') { if (User::can('remove-permission')) { $permission = new Permission(array('user_name' => $user_name, 'permission_name' => $permission_name)); $permission->delete(); - fMessaging::create('success', 'Permission removed successfully.'); + fMessaging::create('success', T('Permission removed successfully.')); } else { - throw new fAuthorizationException('You are not allowed to remove permissions.'); + throw new fAuthorizationException(T('You are not allowed to remove permissions.')); } } } catch (fException $e) { @@ -353,7 +353,7 @@ public function setVariable() if (fRequest::get('remove', 'boolean')) { $variable = new Variable(fRequest::get('name')); $variable->delete(); - fMessaging::create('success', 'Variable removed successfully.'); + fMessaging::create('success', T('Variable removed successfully.')); } else { try { $variable = new Variable(fRequest::get('name')); @@ -363,7 +363,7 @@ public function setVariable() } $variable->setValue(fRequest::get('value')); $variable->store(); - fMessaging::create('success', 'Variable set successfully.'); + fMessaging::create('success', T('Variable set successfully.')); } } catch (fException $e) { fMessaging::create('error', $e->getMessage()); diff --git a/app/controllers/ProblemController.php b/app/controllers/ProblemController.php index 7a07da9..618f2c7 100644 --- a/app/controllers/ProblemController.php +++ b/app/controllers/ProblemController.php @@ -41,7 +41,7 @@ public function show($id) $this->problem = new Problem($id); if ($this->problem->isSecretNow()) { if (!User::can('view-any-problem')) { - throw new fAuthorizationException('Problem is secret now.'); + throw new fAuthorizationException(T('Problem is secret now.')); } } $this->nav_class = 'problems'; diff --git a/app/controllers/RecordController.php b/app/controllers/RecordController.php index 39f6c8e..c8733b1 100644 --- a/app/controllers/RecordController.php +++ b/app/controllers/RecordController.php @@ -30,7 +30,7 @@ public function show($id) try { $this->record = new Record($id); if (!$this->record->isReadable()) { - throw new fAuthorizationException('You are not allowed to read this record.'); + throw new fAuthorizationException(T('You are not allowed to read this record.')); } $this->nav_class = 'status'; $this->render('record/show'); diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index c613f60..beadf38 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -25,7 +25,7 @@ public function show($id) try { $this->report = new Report($id); if (!$this->report->isReadable()) { - throw new fAuthorizationException('You are not allowed to view this report.'); + throw new fAuthorizationException(T('You are not allowed to view this report.')); } global $cache; @@ -64,14 +64,14 @@ public function newRegistration($id) try { $report = new Report($id); if (!$report->isRegistrable()) { - throw new fValidationException('This contest is not registrable.'); + throw new fValidationException(T('This contest is not registrable.')); } $registration = new Registration(); $registration->setUsername(fAuthorization::getUserToken()); $registration->setReportId($report->getId()); $registration->store(); BoardCacheInvalidator::invalidateByReport($report); - fMessaging::create('success', 'Registered successfully.'); + fMessaging::create('success', T('Registered successfully.')); } catch (fExpectedException $e) { fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { @@ -85,11 +85,11 @@ public function newQuestion($id) try { $report = new Report($id); if (!$report->allowQuestion()) { - throw new fValidationException('Not allowed to ask question.'); + throw new fValidationException(T('Not allowed to ask question.')); } $category = fRequest::get('category', 'integer'); if ($category == 0) { - throw new fValidationException('Please choose a category.'); + throw new fValidationException(T('Please choose a category.')); } $question = new Question(); $question->setUsername(fAuthorization::getUserToken()); @@ -104,13 +104,13 @@ public function newQuestion($id) $question->setAskTime(new fTimestamp()); $question->setQuestion(trim(fRequest::get('question'))); if (strlen($question->getQuestion()) < 10) { - throw new fValidationException('Question too short (minimum 10 bytes).'); + throw new fValidationException(T('Question too short (minimum 10 bytes).')); } if (strlen($question->getQuestion()) > 500) { - throw new fValidationException('Question too long (maximum 500 bytes).'); + throw new fValidationException(T('Question too long (maximum 500 bytes).')); } $question->store(); - fMessaging::create('success', 'Question saved.'); + fMessaging::create('success', T('Question saved.')); } catch (fExpectedException $e) { fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { @@ -125,12 +125,12 @@ public function replyQuestion($id) $question = new Question($id); $report = new Report($report_id = $question->getReportId()); if (!$report->allowAnswer()) { - throw new fValidationException('Not allowed to answer question.'); + throw new fValidationException(T('Not allowed to answer question.')); } $question->setAnswerTime(new fTimestamp()); $question->setAnswer(trim(fRequest::get('reply'))); $question->store(); - fMessaging::create('success', 'Question answered.'); + fMessaging::create('success', T('Question answered.')); } catch (fExpectedException $e) { fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { @@ -145,11 +145,11 @@ public function toggleQuestionVisibility($id) $question = new Question($id); $report = new Report($report_id = $question->getReportId()); if (!$report->allowAnswer()) { - throw new fValidationException('Not allowed to toggle question visibility.'); + throw new fValidationException(T('Not allowed to toggle question visibility.')); } $question->setCategory(-$question->getCategory()); $question->store(); - fMessaging::create('success', 'Visibility toggled.'); + fMessaging::create('success', T('Visibility toggled.')); } catch (fExpectedException $e) { fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { diff --git a/app/controllers/SubmitController.php b/app/controllers/SubmitController.php index e7ab59f..b865d52 100644 --- a/app/controllers/SubmitController.php +++ b/app/controllers/SubmitController.php @@ -27,11 +27,11 @@ public function submit($problem_id) fSession::set('last_language', $language); $code = trim(fRequest::get('code', 'string')); if (strlen($code) == 0) { - throw new fValidationException('Code cannot be empty.'); + throw new fValidationException(T('Code cannot be empty.')); } if ($problem->isSecretNow()) { if (!User::can('view-any-problem')) { - throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.'); + throw new fAuthorizationException(T('Problem is secret now. You are not allowed to submit this problem.')); } } diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 695ce03..a508231 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -46,34 +46,34 @@ public function login() $user = new User($username); if ($user->getPassword() == $password_hash) { fAuthorization::setUserToken($user->getUsername()); - fMessaging::create('success', 'Logged in successfully.'); + fMessaging::create('success', T('Logged in successfully.')); fURL::redirect(fAuthorization::getRequestedURL(TRUE, Util::getReferer())); } else { - throw new fValidationException('Password mismatch.'); + throw new fValidationException(T('Password mismatch.')); } } else if (fRequest::get('action') == '注册') { if (strlen($username) < 4) { - throw new fValidationException('Username is too short.'); + throw new fValidationException(T('Username is too short.')); } if (strlen($username) > 20) { - throw new fValidationException('Username is too long.'); + throw new fValidationException(T('Username is too long.')); } if (strlen($password) < 6) { - throw new fValidationException('Password is too short.'); + throw new fValidationException(T('Password is too short.')); } if (Util::contains('`~!@#$%^&*()-+=[]\\;\',/{}|:"<>?', $username) or preg_match('/\s/', $username)) { - throw new fValidationException('Username is illegal.'); + throw new fValidationException(T('Username is illegal.')); } try { $user = new User($username); - throw new fValidationException('User already exists.'); + throw new fValidationException(T('User already exists.')); } catch (fNotFoundException $e) { $user = new User(); $user->setUsername($username); $user->setPassword($password_hash); $user->store(); fAuthorization::setUserToken($user->getUsername()); - fMessaging::create('success', 'Registered successfully.'); + fMessaging::create('success', T('Registered successfully.')); Util::redirect('/email/verify'); } } @@ -86,7 +86,7 @@ public function login() public function logout() { fAuthorization::destroyUserInfo(); - fMessaging::create('success', 'Logged out successfully.'); + fMessaging::create('success', T('Logged out successfully.')); if (strstr(Util::getReferer(), 'contest')) { fURL::redirect(SITE_BASE); } else { @@ -118,7 +118,7 @@ public function updateInfo() $profile->setPhoneNumber($phone_number); $profile->store(); - fMessaging::create('success', 'Information updated successfully.'); + fMessaging::create('success', T('Information updated successfully.')); fURL::redirect(Util::getReferer()); } catch (fException $e) { fMessaging::create('error', $e->getMessage()); @@ -139,23 +139,23 @@ public function updatePassword() $new_password = fRequest::get('new_password'); $repeat_password = fRequest::get('repeat_password'); if (strlen($old_password) < 6) { - throw new fValidationException('Old password is too short.'); + throw new fValidationException(T('Old password is too short.')); } if (strlen($new_password) < 6) { - throw new fValidationException('New password is too short.'); + throw new fValidationException(T('New password is too short.')); } if ($new_password != $repeat_password) { - throw new fValidationException('Repeat password mismatch.'); + throw new fValidationException(T('Repeat password mismatch.')); } $user = new User(fAuthorization::getUserToken()); $old_password_hash = static::hashPassword($old_password); if ($user->getPassword() != $old_password_hash) { - throw new fValidationException('Old password mismatch.'); + throw new fValidationException(T('Old password mismatch.')); } $new_password_hash = static::hashPassword($new_password); $user->setPassword($new_password_hash); $user->store(); - fMessaging::create('success', 'Password updated successfully.'); + fMessaging::create('success', T('Password updated successfully.')); fURL::redirect(Util::getReferer()); } catch (fException $e) { fMessaging::create('error', $e->getMessage()); @@ -224,7 +224,7 @@ public function checkVericode($id, $vericode) try { $v = new Vericode($id); if ($v->getUsername() != fAuthorization::getUserToken() or $v->getVericode() != $vericode) { - throw new fValidationException('Invalid verification code.'); + throw new fValidationException(T('Invalid verification code.')); } $ue = new UserEmail(); @@ -232,12 +232,12 @@ public function checkVericode($id, $vericode) $ue->setEmail($v->getEmail()); $ue->store(); - fMessaging::create('success', 'Your email address is verified successfully.'); + fMessaging::create('success', T('Your email address is verified successfully.')); $referer = fMessaging::retrieve('referer', SITE_BASE . '/email/verify'); if ($referer == NULL) $referer = SITE_BASE; fURL::redirect($referer); } catch (fException $e) { - fMessaging::create('error', 'Email verification failed: ' . $e->getMessage()); + fMessaging::create('error', T('Email verification failed: ') . $e->getMessage()); Util::redirect('/email/verify'); } } diff --git a/app/models/User.php b/app/models/User.php index d9bd256..0adeb4f 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -44,7 +44,7 @@ public static function getVerifiedEmail($username=NULL) } $email = UserEmail::fetch($username); if ($email === NULL) { - return '点击此处进行邮件验证'; + return T('Click here to verify your email address.'); } return $email; } @@ -65,7 +65,7 @@ public static function requireEmailVerified() { if (!fAuthorization::checkLoggedIn()) return; if (User::hasEmailVerified()) return; - fMessaging::create('warning', 'You are required to verify your email address before doing this action.'); + fMessaging::create('warning', T('You are required to verify your email address before doing this action.')); Util::redirect('/email/verify'); } } diff --git a/app/translate.php b/app/translate.php index af0bcaf..7ef1bda 100644 --- a/app/translate.php +++ b/app/translate.php @@ -30,3 +30,93 @@ function translate($string) } return $string; } + +function T($english) +{ + static $translations = array( + 'chinese' => array( + + //app/controllers/DashboardController.php + 'You are not allowed to view the dashboard.' => '你没有进入控制台的权限。', + 'Problem title is not specified in problem.conf'=>'题目名称在 problem.conf 中没有指出。', + 'Problem author is not specified in problem.conf'=>'题目作者在 problem.conf 中没有指出。', + 'Problem case count is not specified in problem.conf'=>'题目数据组数在 problem.conf 中没有指出。', + 'Problem case score is not specified in problem.conf'=>'题目各组数据分数在 problem.conf 中没有指出。', + 'Problem time limit is not specified in problem.conf'=>'题目时间限制在 problem.conf 中没有指出。', + 'Problem memory limit is not specified in problem.conf'=>'题目内存限制在 problem.conf 中没有指出。', + 'Problem secret-before time is not specified in problem.conf'=>'题目隐藏截止时间在 problem.conf 中没有指出。', + 'You are not allowed to manage problems.'=>'你没有管理题目的权限。', + 'All problems refreshed successfully.'=>'所有题目成功刷新。', + 'You are not allowed to rejudge records.'=>'你没有重判记录的权限。', + 'Score cannot be negative.'=>'分数不能为负。', + 'You are not allowed to create reports.'=>'你没有创建比赛的权限。', + 'Report created successfully.'=>'比赛创建成功。', + 'You are not allowed to show this report.'=>'你没有显示此比赛的权限。', + 'You are not allowed to hide this report.'=>'你没有隐藏此比赛的权限。', + 'You are not allowed to remove this report.'=>'你没有删除此比赛的权限。', + 'Permission added successfully.'=>'权限添加成功。', + 'You are not allowed to add permissions.'=>'你没有添加权限的权限。', + 'Permission removed successfully.'=>'权限删除成功。', + 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', + 'Variable removed successfully.'=>'变量删除成功。', + 'Variable set successfully.'=>'变量设置成功。', + + //app/controllers/ProblemController.php + 'Problem is secret now.'=>'题目现在处于隐藏状态。', + + //app/controllers/RecordController.php + 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', + + //app/controllers/ReportController.php + 'You are not allowed to view this report.'=>'你没有查看此比赛的权限。', + 'This contest is not registrable.'=>'比赛不可注册。', + 'Registered successfully.'=>'注册成功。', + 'Not allowed to ask question.'=>'不允许提问。', + 'Please choose a category.'=>'请选择一个分类。', + 'Question too short (minimum 10 bytes).'=>'问题过短 (最少 10 字节)。', + 'Question too long (maximum 500 bytes).'=>'问题过长 (最大 500 字节)。', + 'Question saved.'=>'问题已保存。', + 'Not allowed to answer question.'=>'没有回答问题的权限。', + 'Question answered.'=>'问题已回答。', + 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', + 'Visibility toggled.'=>'可见度已更改。', + + //app/controllers/UserController.php + 'Logged in successfully.'=>'登录成功。', + 'Password mismatch.'=>'密码错误。', + 'Username is too short.'=>'用户名过短。', + 'Username is too long.'=>'用户名过长。', + 'Password is too short.'=>'密码过短。', + 'Username is illegal.'=>'用户名包含非法字符。', + 'User already exists.'=>'用户已存在。', + 'Registered successfully.'=>'注册成功。', + 'Logged out successfully.'=>'注销成功。', + 'Information updated successfully.'=>'信息更新成功。', + 'Old password is too short.'=>'旧密码过短。', + 'New password is too short.'=>'新密码过短。', + 'Repeat password mismatch.'=>'两次输入密码不相同。', + 'Old password mismatch.'=>'旧密码错误。', + 'Password updated successfully.'=>'密码更改成功。', + 'Invalid email address.'=>'邮箱地址无效。', + 'Invalid verification code.'=>'验证码无效。', + 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', + 'Email verification failed: '=>'邮箱验证失败: ', + + //app/controllers/SubmitController.php + 'Code cannot be empty.'=>'代码不能为空。', + 'Problem is secret now. You are not allowed to submit this problem.'=>'问题现在是隐藏状态,你不能提交此题目。', + + + //app/models/User.php + 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', + 'You are required to verify your email address before doing this action.'=>'请先验证你的邮箱地址。' + + + ) + ); + $language = 'chinese'; // 这里先固定为 chinese,以后会修改成根据用户来决定语言 + if (isset($translations[$language][$english])) { + return $translations[$language][$english]; + } + return $english; +} diff --git a/app/views/layout/header.php b/app/views/layout/header.php index ac685fd..f335bf9 100644 --- a/app/views/layout/header.php +++ b/app/views/layout/header.php @@ -126,7 +126,7 @@
× - Warning! + 小心!
@@ -138,12 +138,12 @@
× - Well done! + 啊哈!
× - Heads up! + 提醒!
From eb0a822b9f9e849966abad5097901219b5017efd Mon Sep 17 00:00:00 2001 From: sjtufs Date: Wed, 17 Oct 2012 14:33:00 +0800 Subject: [PATCH 02/13] fix typo --- app/translate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/translate.php b/app/translate.php index 7ef1bda..9a4b116 100644 --- a/app/translate.php +++ b/app/translate.php @@ -104,7 +104,7 @@ function T($english) //app/controllers/SubmitController.php 'Code cannot be empty.'=>'代码不能为空。', - 'Problem is secret now. You are not allowed to submit this problem.'=>'问题现在是隐藏状态,你不能提交此题目。', + 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', //app/models/User.php From d6dc9ef6e02adbc3e1f252c7e3615a5a3d6235a9 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Wed, 17 Oct 2012 23:38:22 +0800 Subject: [PATCH 03/13] change alert message --- app/.translate.php.swp | Bin 0 -> 16384 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/.translate.php.swp diff --git a/app/.translate.php.swp b/app/.translate.php.swp new file mode 100644 index 0000000000000000000000000000000000000000..77b584c9f44db2f48496756e0399cc98406c842c GIT binary patch literal 16384 zcmeHOU2Ggz6`mF-7zjmFq7o0)rA=5Hnm7ppO476{X&)k$)=k@pHp;_z_wMdAvoqV7 zS-V!CvXj`}q;|XwPMp|I+F(5#RjS2I2eLw{3mo;ct@%zVUKBsjw|%AY>q9AY>q9AY>q9AY>q9AY|bGm;obw zuW%RhyBByKxW~ii@bh~>oA+=02tOeMAp;=;Ap;=;Ap;=;Ap;=;Ap;=;Ap;=;Ap`%T z42Us7_zuS2!7l!&|FayxXZH)jUxB{>w}JD(As_}k3v34-1nz!K5G>%2z#=dOoCJOj zP@oOi0elN^HVDFRfYX2k!~hZ40Xzsi0NexI{i-1R3n&3L@LOO8C;&%*O~BGu1mS0Z z{bfN&19zJQVF1_w-2Rdv7{DXIKfWjk<3KyG0hqfFHi1pRpTB^y06zil1AhN`LHHQR z12G^9>;x<%LQG&0NCMvlK0~tPL*N+j7+`_B+W_M*!+2cv(-e75HHaw7YA1~mLnZhE zL?_kA>lvyWlB#Tp?0O<%UAMxyI zBF)x#x0#=GWz6Xj=lJ24x*GMQsu@rzDXz+G^)=e(r@6-2w+Te56t>A!)G3K3RTV!( z62&({5~|kaj>?(2S?WG!y>+QL*Ik^uY-aoHD+~Tms>#$32AM3*4Vt|@PGQa(%7Guh z+g_TGbc1SG0zDIrQeBT{WSQHuu1%SJ16DR?9zXBPzm$}85>*vYWf1&T!5V6=4oz&A zDPOdiVdvLl%;3-r*WvemMa>XVqi(N?mG6*fCo!02jiy1OtEIR&!B^ipf6*R)%bLzx zuHI?~Xm!6o!-k}(vP?C-b+4;rce#asrKTy;z`907_#d|(RW*kZtrQM;<<(3w*IkW;v0FBXDpTkfaPl#0F7sIQrwD4op*`!?j3X(DN=r6gU) zuGWKV>#1@#bTze+wsJ4{MS~IXSg?)}iLqGY;aE2p%;OVW=SstYl6v&;j-Hahwpp2; zhOY0;tC8zB^5~=#qrOMi?kDbC4fj(cr3h~;ZPGJ$?EHLVrF>5k_&p+89na!>+suxc z3-fF8EUw857&Ttys;L_;A}?ZlBEpIa3tjDqMKmEAQU?!Rh^f}8S%fa<$YODB-nm{5 zd<|FdwM;BQF%GuttHx34A2hT1`hg?zlq{1pj|nX9#WkuY>oRk!8?Qk2<{R_&tC_uN zot|AKrlv$i#JGG5!EI+3F4(y~uCvz9y+FmI)aG^?XM`D2iuwUxPt&LrmoQpM@hxmY z1dg*;HrMJoS@yCu{jN1~qcn0I!7U(5igVLmfFI~L`{(`n_;E6YEw6PESxQOeH_aLh zn|-}_<>P!{W^b(5q&vs;8sxM4&kRP{%U*XK(tDS#Wrn$<_QFxPsWn*O{<_|Ix@Mzl zMp+NB+#t8SUV~!Bz~N{e?o(VGce;DmYsQcay!F<@tDkX75Go#3b{}q1ozPSNnQ@+SgS5f@cGXM3a(2b?O=sHBIbl z76{P|M6xK^=zp1*y>H1boVeWQhlF@WiL#?Ld8v6LRT8qKCtC#J7wC!ONJdl0M%~aP zC9xANtaZ7)QsaJ4>Hrgy;-ndGc4{;Std?b3TF4=Y;dcuY$H+Hr+o+RG+wljFES#sB z)@orfj#Fy2EN^_YMmC`?OEOdDu|eDwV7=0OTvJo*47M!FhgEK`?olP^YwV(;rt@d! zt?QMoHH|5pNt2$eHJ6gPGJnaJM58CT+?G@` z<+08VA$0k|?13j8Xvb|PgR{Q(DBD*$dEW2BAJuz;H;1akyiWGyNxuhg=RGQ#MFWQw z#6b~n7#4y(mAQe6@o7>b>7JNGTX5drY&p-6;>U;6?o50_2 zSDyx61s(&ScO@QwZ>Tnox~h@FJA zwi0LQY^i_1?9G~E^JZZb*$;_cDmQo$O&g$#`~aSQiPdw9x1 zHsahxv+o)@IWyDFR5uRVIP5pI2uKHAv}jAx_1^gfq@J-23Wd0;LP;kW`#>s>2Sd=TrtOI&2!x>g8+NGWhr`) zB$3lz(UPmsK77mUUqIRldDoTHqR_x^Xel*D@jo|T)~V*Em7Dk+{iH=Oxl0-(jr2@A zOKP}jKQBS!j>b#KG)M%qWpEQy$lw>}^B6Rj_Y)_(F|>-j7EPrMp2sgP{K}r_DJQk; zOMb4U_R{&HJF==9CtJj4+(mMiO+rzET_WRHHX7SO+@z1Y44gqTf5o|e5$&ux0|u&B z7#wju^|D=oRlRwYrvkZNf1Z1k4pEk3o)T{`QB0n5=sE}HYmH1;r?S(<`9MQvic1%)o*Bl>>DgdD_gOWOz{;zcI<*N@i%P@YLHYGo zsMyv-S&>zBx(Iy()h(Wt<)I2iL8J$f^6@EP;tIQYV)_#5M+s4O8S}(*gXTc5nR~x< z?j7seDOBt158m^;mi?oKxq4hz8uAN}K})>e=xeW*UtY}e(1Pny9!|jB>iL?t1W4Z2 z)cowT3#f7hR-iUYu%T7O2yFFzk}kDNvSf6@`4S1l26uWW0y>jD=KOo0p6?WYhE*j? q-l<%*Bpqda+=bmzu(#I```l`9S$TCnZMiJW%gWW2VO~<^Bl$O1`~T Date: Wed, 17 Oct 2012 23:54:29 +0800 Subject: [PATCH 04/13] change alert message --- app/.translate.php.swp | Bin 16384 -> 0 bytes app/views/layout/header.php | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 app/.translate.php.swp diff --git a/app/.translate.php.swp b/app/.translate.php.swp deleted file mode 100644 index 77b584c9f44db2f48496756e0399cc98406c842c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeHOU2Ggz6`mF-7zjmFq7o0)rA=5Hnm7ppO476{X&)k$)=k@pHp;_z_wMdAvoqV7 zS-V!CvXj`}q;|XwPMp|I+F(5#RjS2I2eLw{3mo;ct@%zVUKBsjw|%AY>q9AY>q9AY>q9AY>q9AY|bGm;obw zuW%RhyBByKxW~ii@bh~>oA+=02tOeMAp;=;Ap;=;Ap;=;Ap;=;Ap;=;Ap;=;Ap`%T z42Us7_zuS2!7l!&|FayxXZH)jUxB{>w}JD(As_}k3v34-1nz!K5G>%2z#=dOoCJOj zP@oOi0elN^HVDFRfYX2k!~hZ40Xzsi0NexI{i-1R3n&3L@LOO8C;&%*O~BGu1mS0Z z{bfN&19zJQVF1_w-2Rdv7{DXIKfWjk<3KyG0hqfFHi1pRpTB^y06zil1AhN`LHHQR z12G^9>;x<%LQG&0NCMvlK0~tPL*N+j7+`_B+W_M*!+2cv(-e75HHaw7YA1~mLnZhE zL?_kA>lvyWlB#Tp?0O<%UAMxyI zBF)x#x0#=GWz6Xj=lJ24x*GMQsu@rzDXz+G^)=e(r@6-2w+Te56t>A!)G3K3RTV!( z62&({5~|kaj>?(2S?WG!y>+QL*Ik^uY-aoHD+~Tms>#$32AM3*4Vt|@PGQa(%7Guh z+g_TGbc1SG0zDIrQeBT{WSQHuu1%SJ16DR?9zXBPzm$}85>*vYWf1&T!5V6=4oz&A zDPOdiVdvLl%;3-r*WvemMa>XVqi(N?mG6*fCo!02jiy1OtEIR&!B^ipf6*R)%bLzx zuHI?~Xm!6o!-k}(vP?C-b+4;rce#asrKTy;z`907_#d|(RW*kZtrQM;<<(3w*IkW;v0FBXDpTkfaPl#0F7sIQrwD4op*`!?j3X(DN=r6gU) zuGWKV>#1@#bTze+wsJ4{MS~IXSg?)}iLqGY;aE2p%;OVW=SstYl6v&;j-Hahwpp2; zhOY0;tC8zB^5~=#qrOMi?kDbC4fj(cr3h~;ZPGJ$?EHLVrF>5k_&p+89na!>+suxc z3-fF8EUw857&Ttys;L_;A}?ZlBEpIa3tjDqMKmEAQU?!Rh^f}8S%fa<$YODB-nm{5 zd<|FdwM;BQF%GuttHx34A2hT1`hg?zlq{1pj|nX9#WkuY>oRk!8?Qk2<{R_&tC_uN zot|AKrlv$i#JGG5!EI+3F4(y~uCvz9y+FmI)aG^?XM`D2iuwUxPt&LrmoQpM@hxmY z1dg*;HrMJoS@yCu{jN1~qcn0I!7U(5igVLmfFI~L`{(`n_;E6YEw6PESxQOeH_aLh zn|-}_<>P!{W^b(5q&vs;8sxM4&kRP{%U*XK(tDS#Wrn$<_QFxPsWn*O{<_|Ix@Mzl zMp+NB+#t8SUV~!Bz~N{e?o(VGce;DmYsQcay!F<@tDkX75Go#3b{}q1ozPSNnQ@+SgS5f@cGXM3a(2b?O=sHBIbl z76{P|M6xK^=zp1*y>H1boVeWQhlF@WiL#?Ld8v6LRT8qKCtC#J7wC!ONJdl0M%~aP zC9xANtaZ7)QsaJ4>Hrgy;-ndGc4{;Std?b3TF4=Y;dcuY$H+Hr+o+RG+wljFES#sB z)@orfj#Fy2EN^_YMmC`?OEOdDu|eDwV7=0OTvJo*47M!FhgEK`?olP^YwV(;rt@d! zt?QMoHH|5pNt2$eHJ6gPGJnaJM58CT+?G@` z<+08VA$0k|?13j8Xvb|PgR{Q(DBD*$dEW2BAJuz;H;1akyiWGyNxuhg=RGQ#MFWQw z#6b~n7#4y(mAQe6@o7>b>7JNGTX5drY&p-6;>U;6?o50_2 zSDyx61s(&ScO@QwZ>Tnox~h@FJA zwi0LQY^i_1?9G~E^JZZb*$;_cDmQo$O&g$#`~aSQiPdw9x1 zHsahxv+o)@IWyDFR5uRVIP5pI2uKHAv}jAx_1^gfq@J-23Wd0;LP;kW`#>s>2Sd=TrtOI&2!x>g8+NGWhr`) zB$3lz(UPmsK77mUUqIRldDoTHqR_x^Xel*D@jo|T)~V*Em7Dk+{iH=Oxl0-(jr2@A zOKP}jKQBS!j>b#KG)M%qWpEQy$lw>}^B6Rj_Y)_(F|>-j7EPrMp2sgP{K}r_DJQk; zOMb4U_R{&HJF==9CtJj4+(mMiO+rzET_WRHHX7SO+@z1Y44gqTf5o|e5$&ux0|u&B z7#wju^|D=oRlRwYrvkZNf1Z1k4pEk3o)T{`QB0n5=sE}HYmH1;r?S(<`9MQvic1%)o*Bl>>DgdD_gOWOz{;zcI<*N@i%P@YLHYGo zsMyv-S&>zBx(Iy()h(Wt<)I2iL8J$f^6@EP;tIQYV)_#5M+s4O8S}(*gXTc5nR~x< z?j7seDOBt158m^;mi?oKxq4hz8uAN}K})>e=xeW*UtY}e(1Pny9!|jB>iL?t1W4Z2 z)cowT3#f7hR-iUYu%T7O2yFFzk}kDNvSf6@`4S1l26uWW0y>jD=KOo0p6?WYhE*j? q-l<%*Bpqda+=bmzu(#I```l`9S$TCnZMiJW%gWW2VO~<^Bl$O1`~T
× - 小心! + 警告!
× - Oh snap! + 喔唷!
× - 啊哈! + 很好!
× - 提醒! + 注意!
From 77fb8154f2ae6516a8498e16b3bc905ba43d468e Mon Sep 17 00:00:00 2001 From: sjtufs Date: Thu, 18 Oct 2012 20:23:00 +0800 Subject: [PATCH 05/13] mode translation in DashboardController --- app/controllers/DashboardController.php | 18 +- app/translate.php | 483 ++++++++++++++++++------ 2 files changed, 376 insertions(+), 125 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index be8d266..c87eeca 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -44,7 +44,7 @@ private function gitPullOriginMaster() { $data_base_dir = Variable::getString('data-base-path'); if (!is_dir($data_base_dir)) { - throw new fValidationException("Data base directory {$data_base_dir} does not exist."); + throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); } $pwd = getcwd(); chdir($data_base_dir); @@ -61,7 +61,7 @@ private function showProblem($id, $ignore_git=FALSE) try { $problem = new Problem($id); if ($problem->exists()) { - throw new fValidationException("Problem {$id} already exists."); + throw new fValidationException(T('Problem %s already exists.'),$id); } } catch (fNotFoundException $e) { // fall through @@ -69,7 +69,7 @@ private function showProblem($id, $ignore_git=FALSE) $data_base_dir = Variable::getString('data-base-path'); if (!is_dir($data_base_dir)) { - throw new fValidationException("Data base directory {$data_base_dir} does not exist."); + throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); } if (!$ignore_git) { @@ -78,22 +78,22 @@ private function showProblem($id, $ignore_git=FALSE) $problem_dir = "{$data_base_dir}/problems/{$id}"; if (!is_dir($problem_dir)) { - throw new fValidationException("Problem directory {$problem_dir} does not exist."); + throw new fValidationException(T('Problem directory %s does not exist.'),$problem_dir); } $problem_conf = "{$problem_dir}/problem.conf"; if (!is_file($problem_conf)) { - throw new fValidationException("Problem configuration file {$problem_conf} does not exist."); + throw new fValidationException(T('Problem configuration file %s does not exist.'),$problem_conf); } $problem_text = "{$problem_dir}/problem.text"; if (!is_file($problem_text)) { - throw new fValidationException("Problem description file {$problem_text} does not exist."); + throw new fValidationException(T('Problem description file %s does not exist.'),$problem_text); } $data_dir = "{$problem_dir}/data"; if (!is_dir($data_dir)) { - throw new fValidationException("Problem {$id} does not have a data directory at {$data_dir}"); + throw new fValidationException(T('Problem %s does not have a data directory at %s.'),$id,$data_dir); } $properties_content = file_get_contents($problem_conf); @@ -140,11 +140,11 @@ private function showProblem($id, $ignore_git=FALSE) for ($t = 1; $t <= $problem->getCaseCount(); $t++) { $input = "{$data_dir}/$t.in"; if (!is_file($input)) { - throw new fValidationException("Case input file {$input} is not found in {$data_dir}"); + throw new fValidationException(T('Case input file %s is not found in %s.'),$input,$data_dir); } $output = "{$data_dir}/$t.out"; if (!is_file($output)) { - throw new fValidationException("Case output file {$output} is not found in {$data_dir}"); + throw new fValidationException(T('Case out file %s is not found in %s.'),$output,$data_dir); } } diff --git a/app/translate.php b/app/translate.php index 9a4b116..c87eeca 100644 --- a/app/translate.php +++ b/app/translate.php @@ -1,122 +1,373 @@ '刚刚', - 'at the same time' => '同时', - 'second' => '秒', - 'seconds' => '秒', - 'minute' => '分钟', - 'minutes' => '分钟', - 'hour' => '小时', - 'hours' => '小时', - 'day' => '天', - 'days' => '天', - 'week' => '周', - 'weeks' => '周', - 'month' => '月', - 'months' => '月', - 'year' => '年', - 'years' => '年', - '%1$s %2$s' => '%1$s %2$s', - '%1$s %2$s from now' => '%1$s %2$s from now', - '%1$s %2$s ago' => '%1$s%2$s前', - '%1$s %2$s after' => '%1$s %2$s after', - '%1$s %2$s before' => '%1$s %2$s before' - ); + public function index() + { + if (!User::can('manage-site')) { + fMessaging::create('error', T('You are not allowed to view the dashboard.')); + fURL::redirect(Util::getReferer()); + } + + if (User::can('view-any-report') or User::can('remove-report')) { + $this->reports = fRecordSet::build('report', array(), array('id' => 'desc')); + } + + if (User::can('add-permission') and User::can('remove-permission')) { + $this->permissions = fRecordSet::build('Permission'); + } + + if (User::can('list-variables')) { + $this->variables = fRecordSet::build('Variable'); + } + + if (User::can('set-variable')) { + if (strlen($edit = fRequest::get('edit'))) { + $this->setvar_name = $edit; + $this->setvar_value = Variable::getString($edit); + $this->setvar_remove = FALSE; + } else if (strlen($remove = fRequest::get('remove'))) { + $this->setvar_name = $remove; + $this->setvar_value = Variable::getString($remove); + $this->setvar_remove = TRUE; + } else { + $this->setvar_name = ''; + $this->setvar_value = ''; + $this->setvar_remove = FALSE; + } + } + + $this->nav_class = 'dashboard'; + $this->render('dashboard/index'); + } - if (isset($translations[$string])) { - return $translations[$string]; + private function gitPullOriginMaster() + { + $data_base_dir = Variable::getString('data-base-path'); + if (!is_dir($data_base_dir)) { + throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); + } + $pwd = getcwd(); + chdir($data_base_dir); + $output = array(); + exec('git pull origin master 2>&1', $output, $retval); + chdir($pwd); + if ($retval != 0) { + throw new fValidationException("
{$data_base_dir}$ git pull origin master\n" . implode("\n", $output) . '
'); + } } - return $string; -} - -function T($english) -{ - static $translations = array( - 'chinese' => array( - - //app/controllers/DashboardController.php - 'You are not allowed to view the dashboard.' => '你没有进入控制台的权限。', - 'Problem title is not specified in problem.conf'=>'题目名称在 problem.conf 中没有指出。', - 'Problem author is not specified in problem.conf'=>'题目作者在 problem.conf 中没有指出。', - 'Problem case count is not specified in problem.conf'=>'题目数据组数在 problem.conf 中没有指出。', - 'Problem case score is not specified in problem.conf'=>'题目各组数据分数在 problem.conf 中没有指出。', - 'Problem time limit is not specified in problem.conf'=>'题目时间限制在 problem.conf 中没有指出。', - 'Problem memory limit is not specified in problem.conf'=>'题目内存限制在 problem.conf 中没有指出。', - 'Problem secret-before time is not specified in problem.conf'=>'题目隐藏截止时间在 problem.conf 中没有指出。', - 'You are not allowed to manage problems.'=>'你没有管理题目的权限。', - 'All problems refreshed successfully.'=>'所有题目成功刷新。', - 'You are not allowed to rejudge records.'=>'你没有重判记录的权限。', - 'Score cannot be negative.'=>'分数不能为负。', - 'You are not allowed to create reports.'=>'你没有创建比赛的权限。', - 'Report created successfully.'=>'比赛创建成功。', - 'You are not allowed to show this report.'=>'你没有显示此比赛的权限。', - 'You are not allowed to hide this report.'=>'你没有隐藏此比赛的权限。', - 'You are not allowed to remove this report.'=>'你没有删除此比赛的权限。', - 'Permission added successfully.'=>'权限添加成功。', - 'You are not allowed to add permissions.'=>'你没有添加权限的权限。', - 'Permission removed successfully.'=>'权限删除成功。', - 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', - 'Variable removed successfully.'=>'变量删除成功。', - 'Variable set successfully.'=>'变量设置成功。', - - //app/controllers/ProblemController.php - 'Problem is secret now.'=>'题目现在处于隐藏状态。', - - //app/controllers/RecordController.php - 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', - - //app/controllers/ReportController.php - 'You are not allowed to view this report.'=>'你没有查看此比赛的权限。', - 'This contest is not registrable.'=>'比赛不可注册。', - 'Registered successfully.'=>'注册成功。', - 'Not allowed to ask question.'=>'不允许提问。', - 'Please choose a category.'=>'请选择一个分类。', - 'Question too short (minimum 10 bytes).'=>'问题过短 (最少 10 字节)。', - 'Question too long (maximum 500 bytes).'=>'问题过长 (最大 500 字节)。', - 'Question saved.'=>'问题已保存。', - 'Not allowed to answer question.'=>'没有回答问题的权限。', - 'Question answered.'=>'问题已回答。', - 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', - 'Visibility toggled.'=>'可见度已更改。', - - //app/controllers/UserController.php - 'Logged in successfully.'=>'登录成功。', - 'Password mismatch.'=>'密码错误。', - 'Username is too short.'=>'用户名过短。', - 'Username is too long.'=>'用户名过长。', - 'Password is too short.'=>'密码过短。', - 'Username is illegal.'=>'用户名包含非法字符。', - 'User already exists.'=>'用户已存在。', - 'Registered successfully.'=>'注册成功。', - 'Logged out successfully.'=>'注销成功。', - 'Information updated successfully.'=>'信息更新成功。', - 'Old password is too short.'=>'旧密码过短。', - 'New password is too short.'=>'新密码过短。', - 'Repeat password mismatch.'=>'两次输入密码不相同。', - 'Old password mismatch.'=>'旧密码错误。', - 'Password updated successfully.'=>'密码更改成功。', - 'Invalid email address.'=>'邮箱地址无效。', - 'Invalid verification code.'=>'验证码无效。', - 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', - 'Email verification failed: '=>'邮箱验证失败: ', - - //app/controllers/SubmitController.php - 'Code cannot be empty.'=>'代码不能为空。', - 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', - - - //app/models/User.php - 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', - 'You are required to verify your email address before doing this action.'=>'请先验证你的邮箱地址。' - - - ) - ); - $language = 'chinese'; // 这里先固定为 chinese,以后会修改成根据用户来决定语言 - if (isset($translations[$language][$english])) { - return $translations[$language][$english]; + + private function showProblem($id, $ignore_git=FALSE) + { + try { + $problem = new Problem($id); + if ($problem->exists()) { + throw new fValidationException(T('Problem %s already exists.'),$id); + } + } catch (fNotFoundException $e) { + // fall through + } + + $data_base_dir = Variable::getString('data-base-path'); + if (!is_dir($data_base_dir)) { + throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); + } + + if (!$ignore_git) { + $this->gitPullOriginMaster(); + } + + $problem_dir = "{$data_base_dir}/problems/{$id}"; + if (!is_dir($problem_dir)) { + throw new fValidationException(T('Problem directory %s does not exist.'),$problem_dir); + } + + $problem_conf = "{$problem_dir}/problem.conf"; + if (!is_file($problem_conf)) { + throw new fValidationException(T('Problem configuration file %s does not exist.'),$problem_conf); + } + + $problem_text = "{$problem_dir}/problem.text"; + if (!is_file($problem_text)) { + throw new fValidationException(T('Problem description file %s does not exist.'),$problem_text); + } + + $data_dir = "{$problem_dir}/data"; + if (!is_dir($data_dir)) { + throw new fValidationException(T('Problem %s does not have a data directory at %s.'),$id,$data_dir); + } + + $properties_content = file_get_contents($problem_conf); + $ini_content = str_replace(': ', ' = ', $properties_content); + $ini = parse_ini_string($ini_content); + if (!array_key_exists('title', $ini) or empty($ini['title'])) { + throw new fValidationException(T('Problem title is not specified in problem.conf')); + } + if (!array_key_exists('author', $ini)) { + throw new fValidationException(T('Problem author is not specified in problem.conf')); + } + if (!array_key_exists('case_count', $ini) or empty($ini['case_count'])) { + throw new fValidationException(T('Problem case count is not specified in problem.conf')); + } + if (!array_key_exists('case_score', $ini) or empty($ini['case_score'])) { + throw new fValidationException(T('Problem case score is not specified in problem.conf')); + } + if (!array_key_exists('time_limit', $ini) or empty($ini['time_limit'])) { + throw new fValidationException(T('Problem time limit is not specified in problem.conf')); + } + if (!array_key_exists('memory_limit', $ini) or empty($ini['memory_limit'])) { + throw new fValidationException(T('Problem memory limit is not specified in problem.conf')); + } + if (!array_key_exists('secret_before', $ini) or empty($ini['secret_before'])) { + throw new fValidationException(T('Problem secret-before time is not specified in problem.conf')); + } + + if (empty($ini['author'])) { + $ini['author'] = '-'; + } + + $problem = new Problem(); + $problem->setId($id); + $problem->setTitle($ini['title']); + $problem->setDescription(file_get_contents($problem_text)); + $problem->setAuthor($ini['author']); + $problem->setCaseCount($ini['case_count']); + $problem->setCaseScore($ini['case_score']); + $problem->setTimeLimit($ini['time_limit']); + $problem->setMemoryLimit($ini['memory_limit']); + $problem->setSecretBefore($ini['secret_before']); + $problem->validate(); + + for ($t = 1; $t <= $problem->getCaseCount(); $t++) { + $input = "{$data_dir}/$t.in"; + if (!is_file($input)) { + throw new fValidationException(T('Case input file %s is not found in %s.'),$input,$data_dir); + } + $output = "{$data_dir}/$t.out"; + if (!is_file($output)) { + throw new fValidationException(T('Case out file %s is not found in %s.'),$output,$data_dir); + } + } + + $problem->store(); + } + + private function hideProblem($id) + { + $problem = new Problem($id); + $problem->delete(); + } + + private function refreshProblem($id) + { + $db = fORMDatabase::retrieve(); + try { + $db->query('BEGIN'); + $this->hideProblem($id); + $this->showProblem($id); + $db->query('COMMIT'); + } catch (fException $e) { + $db->query('ROLLBACK'); + throw $e; + } + } + + private function refreshAllProblems() + { + set_time_limit(0); + $db = fORMDatabase::retrieve(); + try { + $db->query('BEGIN'); + $this->gitPullOriginMaster(); + $problems = fRecordSet::build('Problem'); + foreach ($problems as $problem) { + $id = $problem->getId(); + $this->hideProblem($id); + $this->showProblem($id, TRUE); // ignore git + } + $db->query('COMMIT'); + } catch (fExpectedException $e) { + $db->query('ROLLBACK'); + throw new fExpectedException($id . ': ' . $e->getMessage()); + } catch (fUnexpectedException $e) { + $db->query('ROLLBACK'); + throw new fUnexpectedException($id . ': ' . $e->getMessage()); + } + } + + public function manageProblem($id, $action) + { + try { + if (!User::can('manage-site')) { + throw new fAuthorizationException(T('You are not allowed to manage problems.')); + } + if ($action == 'Show') { + $this->showProblem($id); + fMessaging::create('success', "Problem {$id} showed successfully."); + } else if ($action == 'Hide') { + $this->hideProblem($id); + fMessaging::create('success', "Problem {$id} hidden successfully."); + } else if ($action == 'Refresh') { + $this->refreshProblem($id); + fMessaging::create('success', "Problem {$id} refreshed successfully."); + } else if ($action == 'Refresh All' and User::can('refresh-all')) { + $this->refreshAllProblems(); + fMessaging::create('success', T('All problems refreshed successfully.')); + } + } catch (fException $e) { + fMessaging::create('error', $e->getMessage()); + } + fURL::redirect(Util::getReferer()); + } + + public function rejudge($id) + { + try { + if (!User::can('rejudge-record')) { + throw new fAuthorizationException(T('You are not allowed to rejudge records.')); + } + $old_record = new Record($id); + $new_record = new Record(); + $new_record->setOwner($old_record->getOwner()); + $new_record->setProblemId($old_record->getProblemId()); + $new_record->setSubmitCode($old_record->getSubmitCode()); + $new_record->setCodeLanguage($old_record->getCodeLanguage()); + $new_record->setSubmitDatetime($old_record->getSubmitDatetime()); + $new_record->setJudgeStatus(JudgeStatus::PENDING); + $new_record->setJudgeMessage('Rejudging... PROB=' . $old_record->getProblemId() . ' LANG=' . $old_record->getLanguageName()); + $new_record->setVerdict(Verdict::UNKNOWN); + $new_record->store(); + fMessaging::create('success', "Record {$id} rejudged."); + } catch (fException $e) { + fMessaging::create('error', $e->getMessage()); + } + fURL::redirect(Util::getReferer()); + } + + public function manjudge($id, $score) + { + try { + if (!User::can('rejudge-record')) { + throw new fAuthorizationException(T('You are not allowed to rejudge records.')); + } + if ($score < 0) { + throw new fValidationException(T('Score cannot be negative.')); + } + $record = new Record($id); + $record->manjudge($score); + $record->store(); + fMessaging::create('success', "Record {$id} manually judged."); + } catch (fException $e) { + fMessaging::create('error', $e->getMessage()); + } + fURL::redirect(Util::getReferer()); + } + + public function createReport() + { + try { + if (!User::can('create-report')) { + throw new fAuthorizationException(T('You are not allowed to create reports.')); + } + $report = new Report(); + $report->setVisible(fRequest::get('visible', 'integer')); + $report->setTitle(fRequest::get('title', 'string')); + $report->setProblemList(fRequest::get('problem_list', 'string')); + $report->setUserList(fRequest::get('user_list', 'string')); + $report->setStartDatetime(fRequest::get('start_time', 'timestamp')); + $report->setEndDatetime(fRequest::get('end_time', 'timestamp')); + $report->store(); + fMessaging::create('success', T('Report created successfully.')); + } catch (fException $e) { + fMessaging::create('error', $e->getMessage()); + } + fURL::redirect(Util::getReferer()); + } + + public function manageReport($id, $action) + { + try { + $report = new Report($id); + if ($action == 'Show') { + if (User::can('view-any-report')) { + $report->setVisible(1); + $report->store(); + fMessaging::create('success', "Report {$id} showed successfully."); + } else { + throw new fAuthorizationException(T('You are not allowed to show this report.')); + } + } else if ($action == 'Hide') { + if (User::can('view-any-report')) { + $report->setVisible(0); + $report->store(); + fMessaging::create('success', "Report {$id} hidden successfully."); + } else { + throw new fAuthorizationException(T('You are not allowed to hide this report.')); + } + } else if ($action == 'Remove') { + if (User::can('remove-report')) { + $report->delete(); + fMessaging::create('success', "Report {$id} removed successfully."); + } else { + throw new fAuthorizationException(T('You are not allowed to remove this report.')); + } + } + } catch (fException $e) { + fMessaging::create('error', $e->getMessage()); + } + fURL::redirect(Util::getReferer()); + } + + public function managePermission($action) + { + try { + $user_name = fRequest::get('user_name'); + $permission_name = fRequest::get('permission_name'); + if ($action == 'Add') { + if (User::can('add-permission')) { + $permission = new Permission(); + $permission->setUserName($user_name); + $permission->setPermissionName($permission_name); + $permission->store(); + fMessaging::create('success', T('Permission added successfully.')); + } else { + throw new fAuthorizationException(T('You are not allowed to add permissions.')); + } + } else if ($action == 'Remove') { + if (User::can('remove-permission')) { + $permission = new Permission(array('user_name' => $user_name, 'permission_name' => $permission_name)); + $permission->delete(); + fMessaging::create('success', T('Permission removed successfully.')); + } else { + throw new fAuthorizationException(T('You are not allowed to remove permissions.')); + } + } + } catch (fException $e) { + fMessaging::create('error', $e->getMessage()); + } + fURL::redirect(Util::getReferer()); + } + + public function setVariable() + { + try { + if (fRequest::get('remove', 'boolean')) { + $variable = new Variable(fRequest::get('name')); + $variable->delete(); + fMessaging::create('success', T('Variable removed successfully.')); + } else { + try { + $variable = new Variable(fRequest::get('name')); + } catch (fNotFoundException $e) { + $variable = new Variable(); + $variable->setName(fRequest::get('name')); + } + $variable->setValue(fRequest::get('value')); + $variable->store(); + fMessaging::create('success', T('Variable set successfully.')); + } + } catch (fException $e) { + fMessaging::create('error', $e->getMessage()); + } + fURL::redirect(Util::getReferer()); } - return $english; } From dc358831c64ea269ca461f8c99250988cdd4d7db Mon Sep 17 00:00:00 2001 From: sjtufs Date: Thu, 18 Oct 2012 20:25:33 +0800 Subject: [PATCH 06/13] replacement of translate --- app/translate.php | 496 ++++++++++++---------------------------------- 1 file changed, 129 insertions(+), 367 deletions(-) diff --git a/app/translate.php b/app/translate.php index c87eeca..acc3153 100644 --- a/app/translate.php +++ b/app/translate.php @@ -1,373 +1,135 @@ reports = fRecordSet::build('report', array(), array('id' => 'desc')); - } - - if (User::can('add-permission') and User::can('remove-permission')) { - $this->permissions = fRecordSet::build('Permission'); - } - - if (User::can('list-variables')) { - $this->variables = fRecordSet::build('Variable'); - } - - if (User::can('set-variable')) { - if (strlen($edit = fRequest::get('edit'))) { - $this->setvar_name = $edit; - $this->setvar_value = Variable::getString($edit); - $this->setvar_remove = FALSE; - } else if (strlen($remove = fRequest::get('remove'))) { - $this->setvar_name = $remove; - $this->setvar_value = Variable::getString($remove); - $this->setvar_remove = TRUE; - } else { - $this->setvar_name = ''; - $this->setvar_value = ''; - $this->setvar_remove = FALSE; - } - } - - $this->nav_class = 'dashboard'; - $this->render('dashboard/index'); - } - - private function gitPullOriginMaster() - { - $data_base_dir = Variable::getString('data-base-path'); - if (!is_dir($data_base_dir)) { - throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); - } - $pwd = getcwd(); - chdir($data_base_dir); - $output = array(); - exec('git pull origin master 2>&1', $output, $retval); - chdir($pwd); - if ($retval != 0) { - throw new fValidationException("
{$data_base_dir}$ git pull origin master\n" . implode("\n", $output) . '
'); - } - } - - private function showProblem($id, $ignore_git=FALSE) - { - try { - $problem = new Problem($id); - if ($problem->exists()) { - throw new fValidationException(T('Problem %s already exists.'),$id); - } - } catch (fNotFoundException $e) { - // fall through - } - - $data_base_dir = Variable::getString('data-base-path'); - if (!is_dir($data_base_dir)) { - throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); - } - - if (!$ignore_git) { - $this->gitPullOriginMaster(); - } - - $problem_dir = "{$data_base_dir}/problems/{$id}"; - if (!is_dir($problem_dir)) { - throw new fValidationException(T('Problem directory %s does not exist.'),$problem_dir); - } - - $problem_conf = "{$problem_dir}/problem.conf"; - if (!is_file($problem_conf)) { - throw new fValidationException(T('Problem configuration file %s does not exist.'),$problem_conf); - } - - $problem_text = "{$problem_dir}/problem.text"; - if (!is_file($problem_text)) { - throw new fValidationException(T('Problem description file %s does not exist.'),$problem_text); - } - - $data_dir = "{$problem_dir}/data"; - if (!is_dir($data_dir)) { - throw new fValidationException(T('Problem %s does not have a data directory at %s.'),$id,$data_dir); - } - - $properties_content = file_get_contents($problem_conf); - $ini_content = str_replace(': ', ' = ', $properties_content); - $ini = parse_ini_string($ini_content); - if (!array_key_exists('title', $ini) or empty($ini['title'])) { - throw new fValidationException(T('Problem title is not specified in problem.conf')); - } - if (!array_key_exists('author', $ini)) { - throw new fValidationException(T('Problem author is not specified in problem.conf')); - } - if (!array_key_exists('case_count', $ini) or empty($ini['case_count'])) { - throw new fValidationException(T('Problem case count is not specified in problem.conf')); - } - if (!array_key_exists('case_score', $ini) or empty($ini['case_score'])) { - throw new fValidationException(T('Problem case score is not specified in problem.conf')); - } - if (!array_key_exists('time_limit', $ini) or empty($ini['time_limit'])) { - throw new fValidationException(T('Problem time limit is not specified in problem.conf')); - } - if (!array_key_exists('memory_limit', $ini) or empty($ini['memory_limit'])) { - throw new fValidationException(T('Problem memory limit is not specified in problem.conf')); - } - if (!array_key_exists('secret_before', $ini) or empty($ini['secret_before'])) { - throw new fValidationException(T('Problem secret-before time is not specified in problem.conf')); - } - - if (empty($ini['author'])) { - $ini['author'] = '-'; - } - - $problem = new Problem(); - $problem->setId($id); - $problem->setTitle($ini['title']); - $problem->setDescription(file_get_contents($problem_text)); - $problem->setAuthor($ini['author']); - $problem->setCaseCount($ini['case_count']); - $problem->setCaseScore($ini['case_score']); - $problem->setTimeLimit($ini['time_limit']); - $problem->setMemoryLimit($ini['memory_limit']); - $problem->setSecretBefore($ini['secret_before']); - $problem->validate(); - - for ($t = 1; $t <= $problem->getCaseCount(); $t++) { - $input = "{$data_dir}/$t.in"; - if (!is_file($input)) { - throw new fValidationException(T('Case input file %s is not found in %s.'),$input,$data_dir); - } - $output = "{$data_dir}/$t.out"; - if (!is_file($output)) { - throw new fValidationException(T('Case out file %s is not found in %s.'),$output,$data_dir); - } - } - - $problem->store(); - } - - private function hideProblem($id) - { - $problem = new Problem($id); - $problem->delete(); - } - - private function refreshProblem($id) - { - $db = fORMDatabase::retrieve(); - try { - $db->query('BEGIN'); - $this->hideProblem($id); - $this->showProblem($id); - $db->query('COMMIT'); - } catch (fException $e) { - $db->query('ROLLBACK'); - throw $e; - } - } - - private function refreshAllProblems() - { - set_time_limit(0); - $db = fORMDatabase::retrieve(); - try { - $db->query('BEGIN'); - $this->gitPullOriginMaster(); - $problems = fRecordSet::build('Problem'); - foreach ($problems as $problem) { - $id = $problem->getId(); - $this->hideProblem($id); - $this->showProblem($id, TRUE); // ignore git - } - $db->query('COMMIT'); - } catch (fExpectedException $e) { - $db->query('ROLLBACK'); - throw new fExpectedException($id . ': ' . $e->getMessage()); - } catch (fUnexpectedException $e) { - $db->query('ROLLBACK'); - throw new fUnexpectedException($id . ': ' . $e->getMessage()); - } - } - - public function manageProblem($id, $action) - { - try { - if (!User::can('manage-site')) { - throw new fAuthorizationException(T('You are not allowed to manage problems.')); - } - if ($action == 'Show') { - $this->showProblem($id); - fMessaging::create('success', "Problem {$id} showed successfully."); - } else if ($action == 'Hide') { - $this->hideProblem($id); - fMessaging::create('success', "Problem {$id} hidden successfully."); - } else if ($action == 'Refresh') { - $this->refreshProblem($id); - fMessaging::create('success', "Problem {$id} refreshed successfully."); - } else if ($action == 'Refresh All' and User::can('refresh-all')) { - $this->refreshAllProblems(); - fMessaging::create('success', T('All problems refreshed successfully.')); - } - } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); - } - fURL::redirect(Util::getReferer()); - } - - public function rejudge($id) - { - try { - if (!User::can('rejudge-record')) { - throw new fAuthorizationException(T('You are not allowed to rejudge records.')); - } - $old_record = new Record($id); - $new_record = new Record(); - $new_record->setOwner($old_record->getOwner()); - $new_record->setProblemId($old_record->getProblemId()); - $new_record->setSubmitCode($old_record->getSubmitCode()); - $new_record->setCodeLanguage($old_record->getCodeLanguage()); - $new_record->setSubmitDatetime($old_record->getSubmitDatetime()); - $new_record->setJudgeStatus(JudgeStatus::PENDING); - $new_record->setJudgeMessage('Rejudging... PROB=' . $old_record->getProblemId() . ' LANG=' . $old_record->getLanguageName()); - $new_record->setVerdict(Verdict::UNKNOWN); - $new_record->store(); - fMessaging::create('success', "Record {$id} rejudged."); - } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); - } - fURL::redirect(Util::getReferer()); - } - - public function manjudge($id, $score) - { - try { - if (!User::can('rejudge-record')) { - throw new fAuthorizationException(T('You are not allowed to rejudge records.')); - } - if ($score < 0) { - throw new fValidationException(T('Score cannot be negative.')); - } - $record = new Record($id); - $record->manjudge($score); - $record->store(); - fMessaging::create('success', "Record {$id} manually judged."); - } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); - } - fURL::redirect(Util::getReferer()); - } - - public function createReport() - { - try { - if (!User::can('create-report')) { - throw new fAuthorizationException(T('You are not allowed to create reports.')); - } - $report = new Report(); - $report->setVisible(fRequest::get('visible', 'integer')); - $report->setTitle(fRequest::get('title', 'string')); - $report->setProblemList(fRequest::get('problem_list', 'string')); - $report->setUserList(fRequest::get('user_list', 'string')); - $report->setStartDatetime(fRequest::get('start_time', 'timestamp')); - $report->setEndDatetime(fRequest::get('end_time', 'timestamp')); - $report->store(); - fMessaging::create('success', T('Report created successfully.')); - } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); - } - fURL::redirect(Util::getReferer()); - } - - public function manageReport($id, $action) - { - try { - $report = new Report($id); - if ($action == 'Show') { - if (User::can('view-any-report')) { - $report->setVisible(1); - $report->store(); - fMessaging::create('success', "Report {$id} showed successfully."); - } else { - throw new fAuthorizationException(T('You are not allowed to show this report.')); - } - } else if ($action == 'Hide') { - if (User::can('view-any-report')) { - $report->setVisible(0); - $report->store(); - fMessaging::create('success', "Report {$id} hidden successfully."); - } else { - throw new fAuthorizationException(T('You are not allowed to hide this report.')); - } - } else if ($action == 'Remove') { - if (User::can('remove-report')) { - $report->delete(); - fMessaging::create('success', "Report {$id} removed successfully."); - } else { - throw new fAuthorizationException(T('You are not allowed to remove this report.')); - } - } - } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); - } - fURL::redirect(Util::getReferer()); - } + static $translations = array( + 'right now' => '刚刚', + 'at the same time' => '同时', + 'second' => '秒', + 'seconds' => '秒', + 'minute' => '分钟', + 'minutes' => '分钟', + 'hour' => '小时', + 'hours' => '小时', + 'day' => '天', + 'days' => '天', + 'week' => '周', + 'weeks' => '周', + 'month' => '月', + 'months' => '月', + 'year' => '年', + 'years' => '年', + '%1$s %2$s' => '%1$s %2$s', + '%1$s %2$s from now' => '%1$s %2$s from now', + '%1$s %2$s ago' => '%1$s%2$s前', + '%1$s %2$s after' => '%1$s %2$s after', + '%1$s %2$s before' => '%1$s %2$s before' + ); - public function managePermission($action) - { - try { - $user_name = fRequest::get('user_name'); - $permission_name = fRequest::get('permission_name'); - if ($action == 'Add') { - if (User::can('add-permission')) { - $permission = new Permission(); - $permission->setUserName($user_name); - $permission->setPermissionName($permission_name); - $permission->store(); - fMessaging::create('success', T('Permission added successfully.')); - } else { - throw new fAuthorizationException(T('You are not allowed to add permissions.')); - } - } else if ($action == 'Remove') { - if (User::can('remove-permission')) { - $permission = new Permission(array('user_name' => $user_name, 'permission_name' => $permission_name)); - $permission->delete(); - fMessaging::create('success', T('Permission removed successfully.')); - } else { - throw new fAuthorizationException(T('You are not allowed to remove permissions.')); - } - } - } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); - } - fURL::redirect(Util::getReferer()); + if (isset($translations[$string])) { + return $translations[$string]; } - - public function setVariable() - { - try { - if (fRequest::get('remove', 'boolean')) { - $variable = new Variable(fRequest::get('name')); - $variable->delete(); - fMessaging::create('success', T('Variable removed successfully.')); - } else { - try { - $variable = new Variable(fRequest::get('name')); - } catch (fNotFoundException $e) { - $variable = new Variable(); - $variable->setName(fRequest::get('name')); - } - $variable->setValue(fRequest::get('value')); - $variable->store(); - fMessaging::create('success', T('Variable set successfully.')); - } - } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); - } - fURL::redirect(Util::getReferer()); + return $string; +} + +function T($english) +{ + static $translations = array( + 'chinese' => array( + + //app/controllers/DashboardController.php + 'You are not allowed to view the dashboard.' => '你没有进入控制台的权限。', + 'Problem title is not specified in problem.conf'=>'题目名称在 problem.conf 中没有指出。', + 'Problem author is not specified in problem.conf'=>'题目作者在 problem.conf 中没有指出。', + 'Problem case count is not specified in problem.conf'=>'题目数据组数在 problem.conf 中没有指出。', + 'Problem case score is not specified in problem.conf'=>'题目各组数据分数在 problem.conf 中没有指出。', + 'Problem time limit is not specified in problem.conf'=>'题目时间限制在 problem.conf 中没有指出。', + 'Problem memory limit is not specified in problem.conf'=>'题目内存限制在 problem.conf 中没有指出。', + 'Problem secret-before time is not specified in problem.conf'=>'题目隐藏截止时间在 problem.conf 中没有指出。', + 'You are not allowed to manage problems.'=>'你没有管理题目的权限。', + 'All problems refreshed successfully.'=>'所有题目成功刷新。', + 'You are not allowed to rejudge records.'=>'你没有重判记录的权限。', + 'Score cannot be negative.'=>'分数不能为负。', + 'You are not allowed to create reports.'=>'你没有创建比赛的权限。', + 'Report created successfully.'=>'比赛创建成功。', + 'You are not allowed to show this report.'=>'你没有显示此比赛的权限。', + 'You are not allowed to hide this report.'=>'你没有隐藏此比赛的权限。', + 'You are not allowed to remove this report.'=>'你没有删除此比赛的权限。', + 'Permission added successfully.'=>'权限添加成功。', + 'You are not allowed to add permissions.'=>'你没有添加权限的权限。', + 'Permission removed successfully.'=>'权限删除成功。', + 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', + 'Variable removed successfully.'=>'变量删除成功。', + 'Variable set successfully.'=>'变量设置成功。', + + 'Data base directory %s does not exist.'=>'数据目录 %s 不存在。', + 'Problem %s already exists.'=>'题目 %s 已存在。', + 'Problem directory %s does not exist.'=>'题目目录 %s 不存在。', + 'Problem configuration file %s does not exist.'=>'题目配置文件 %s 不存在。', + 'Problem description file %s does not exist.'=>'题目描述文件 %s 不存在。', + 'Problem %s does not have a data directory at %s.'=>'题目 %s 在 %s 没有数据目录。', + 'Case input file %s is not found in %s.'=>'数据输入文件 %s 在 %s 没有找到。', + 'Case output file %s is not found in %s.'=>'数据输出文件 %s 在 %s 没有找到。', + 'Problem %s showed successfully.'=>'题目 " . func_get_args(1) . " 显示成功。', + 'Problem %s hidden successfully.'=>'题目 %s 隐藏成功。', + 'User'=>'用户', + 'Record'=>'比赛记录', + + //app/controllers/ProblemController.php + 'Problem is secret now.'=>'题目现在处于隐藏状态。', + + //app/controllers/RecordController.php + 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', + + //app/controllers/ReportController.php + 'You are not allowed to view this report.'=>'你没有查看此比赛的权限。', + 'This contest is not registrable.'=>'比赛不可注册。', + 'Registered successfully.'=>'注册成功。', + 'Not allowed to ask question.'=>'不允许提问。', + 'Please choose a category.'=>'请选择一个分类。', + 'Question too short (minimum 10 bytes).'=>'问题过短 (最少 10 字节)。', + 'Question too long (maximum 500 bytes).'=>'问题过长 (最大 500 字节)。', + 'Question saved.'=>'问题已保存。', + 'Not allowed to answer question.'=>'没有回答问题的权限。', + 'Question answered.'=>'问题已回答。', + 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', + 'Visibility toggled.'=>'可见度已更改。', + + //app/controllers/UserController.php + 'Logged in successfully.'=>'登录成功。', + 'Password mismatch.'=>'密码错误。', + 'Username is too short.'=>'用户名过短。', + 'Username is too long.'=>'用户名过长。', + 'Password is too short.'=>'密码过短。', + 'Username is illegal.'=>'用户名包含非法字符。', + 'User already exists.'=>'用户已存在。', + 'Registered successfully.'=>'注册成功。', + 'Logged out successfully.'=>'注销成功。', + 'Information updated successfully.'=>'信息更新成功。', + 'Old password is too short.'=>'旧密码过短。', + 'New password is too short.'=>'新密码过短。', + 'Repeat password mismatch.'=>'两次输入密码不相同。', + 'Old password mismatch.'=>'旧密码错误。', + 'Password updated successfully.'=>'密码更改成功。', + 'Invalid email address.'=>'邮箱地址无效。', + 'Invalid verification code.'=>'验证码无效。', + 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', + 'Email verification failed: '=>'邮箱验证失败: ', + + //app/controllers/SubmitController.php + 'Code cannot be empty.'=>'代码不能为空。', + 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', + + + //app/models/User.php + 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', + 'You are required to verify your email address before doing this action.'=>'请先验证你的邮箱地址。' + + + ) + ); + $language = 'chinese'; // 这里先固定为 chinese,以后会修改成根据用户来决定语言 + if (isset($translations[$language][$english])) { + return $translations[$language][$english]; } + return $english; } From 3ce7bc9944f7cef1313f8f9495094f9cb69e8b5c Mon Sep 17 00:00:00 2001 From: sjtufs Date: Thu, 18 Oct 2012 20:58:14 +0800 Subject: [PATCH 07/13] Dashboard controller finished --- app/controllers/DashboardController.php | 16 ++++++++-------- app/translate.php | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index c87eeca..78917c3 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -202,13 +202,13 @@ public function manageProblem($id, $action) } if ($action == 'Show') { $this->showProblem($id); - fMessaging::create('success', "Problem {$id} showed successfully."); + fMessaging::create('success', T('Problem %s showed successfully.',$id)); } else if ($action == 'Hide') { $this->hideProblem($id); - fMessaging::create('success', "Problem {$id} hidden successfully."); + fMessaging::create('success', T('Problem %s hidden successfully.',$id)); } else if ($action == 'Refresh') { $this->refreshProblem($id); - fMessaging::create('success', "Problem {$id} refreshed successfully."); + fMessaging::create('success', T('Problem %s refreshed successfully.',$id)); } else if ($action == 'Refresh All' and User::can('refresh-all')) { $this->refreshAllProblems(); fMessaging::create('success', T('All problems refreshed successfully.')); @@ -236,7 +236,7 @@ public function rejudge($id) $new_record->setJudgeMessage('Rejudging... PROB=' . $old_record->getProblemId() . ' LANG=' . $old_record->getLanguageName()); $new_record->setVerdict(Verdict::UNKNOWN); $new_record->store(); - fMessaging::create('success', "Record {$id} rejudged."); + fMessaging::create('success', T('Record %s rejudged.',$id)); } catch (fException $e) { fMessaging::create('error', $e->getMessage()); } @@ -255,7 +255,7 @@ public function manjudge($id, $score) $record = new Record($id); $record->manjudge($score); $record->store(); - fMessaging::create('success', "Record {$id} manually judged."); + fMessaging::create('success', T('Record %s manually judged.',$id)); } catch (fException $e) { fMessaging::create('error', $e->getMessage()); } @@ -291,7 +291,7 @@ public function manageReport($id, $action) if (User::can('view-any-report')) { $report->setVisible(1); $report->store(); - fMessaging::create('success', "Report {$id} showed successfully."); + fMessaging::create('success', T('Report %s showed successfully.',$id)); } else { throw new fAuthorizationException(T('You are not allowed to show this report.')); } @@ -299,14 +299,14 @@ public function manageReport($id, $action) if (User::can('view-any-report')) { $report->setVisible(0); $report->store(); - fMessaging::create('success', "Report {$id} hidden successfully."); + fMessaging::create('success', T('Report %s hidden successfully.',$id)); } else { throw new fAuthorizationException(T('You are not allowed to hide this report.')); } } else if ($action == 'Remove') { if (User::can('remove-report')) { $report->delete(); - fMessaging::create('success', "Report {$id} removed successfully."); + fMessaging::create('success', T('Report %s removed successfully.',$id)); } else { throw new fAuthorizationException(T('You are not allowed to remove this report.')); } diff --git a/app/translate.php b/app/translate.php index acc3153..0e8685b 100644 --- a/app/translate.php +++ b/app/translate.php @@ -33,6 +33,7 @@ function translate($string) function T($english) { + $numargs=func_num_args(); static $translations = array( 'chinese' => array( @@ -69,8 +70,14 @@ function T($english) 'Problem %s does not have a data directory at %s.'=>'题目 %s 在 %s 没有数据目录。', 'Case input file %s is not found in %s.'=>'数据输入文件 %s 在 %s 没有找到。', 'Case output file %s is not found in %s.'=>'数据输出文件 %s 在 %s 没有找到。', - 'Problem %s showed successfully.'=>'题目 " . func_get_args(1) . " 显示成功。', + 'Problem %s showed successfully.'=>'题目 %s 显示成功。', 'Problem %s hidden successfully.'=>'题目 %s 隐藏成功。', + 'Problem %s refreshed successfully.'=>'题目 %s 刷新成功。', + 'Record %s rejudged.'=>'提交记录 %s 已重判。', + 'Record %s manually judged.'=>'提交记录 %s 已人工判定。', + 'Report %s showed successfully.'=>'比赛 %s 已成功显示。', + 'Report %s hidden successfully.'=>'比赛 %s 已成功隐藏。', + 'Report %s removed successfully.'=>'比赛 %s 已成功移除。', 'User'=>'用户', 'Record'=>'比赛记录', @@ -129,6 +136,19 @@ function T($english) ); $language = 'chinese'; // 这里先固定为 chinese,以后会修改成根据用户来决定语言 if (isset($translations[$language][$english])) { + if($numargs==2){ + $arg2=func_get_arg(1); + $t=$translations[$language][$english]; + $translation=sprintf("$t",$arg2); + return $translation; + } + if($numargs==3){ + $arg2=func_get_arg(1); + $arg3=func_get_arg(2); + $t=$translations[$language][$english]; + $translation=sprintf("$t",$arg2,$arg3); + return $translation; + } return $translations[$language][$english]; } return $english; From 8c083d7e0f0f05149072094402239168f1993f53 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Sat, 20 Oct 2012 17:36:52 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=A9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/translate.php | 181 +++++++++++++++++++++++----------------------- 1 file changed, 90 insertions(+), 91 deletions(-) diff --git a/app/translate.php b/app/translate.php index 0e8685b..c4a7cb4 100644 --- a/app/translate.php +++ b/app/translate.php @@ -37,102 +37,101 @@ function T($english) static $translations = array( 'chinese' => array( - //app/controllers/DashboardController.php - 'You are not allowed to view the dashboard.' => '你没有进入控制台的权限。', - 'Problem title is not specified in problem.conf'=>'题目名称在 problem.conf 中没有指出。', - 'Problem author is not specified in problem.conf'=>'题目作者在 problem.conf 中没有指出。', - 'Problem case count is not specified in problem.conf'=>'题目数据组数在 problem.conf 中没有指出。', - 'Problem case score is not specified in problem.conf'=>'题目各组数据分数在 problem.conf 中没有指出。', - 'Problem time limit is not specified in problem.conf'=>'题目时间限制在 problem.conf 中没有指出。', - 'Problem memory limit is not specified in problem.conf'=>'题目内存限制在 problem.conf 中没有指出。', - 'Problem secret-before time is not specified in problem.conf'=>'题目隐藏截止时间在 problem.conf 中没有指出。', - 'You are not allowed to manage problems.'=>'你没有管理题目的权限。', - 'All problems refreshed successfully.'=>'所有题目成功刷新。', - 'You are not allowed to rejudge records.'=>'你没有重判记录的权限。', - 'Score cannot be negative.'=>'分数不能为负。', - 'You are not allowed to create reports.'=>'你没有创建比赛的权限。', - 'Report created successfully.'=>'比赛创建成功。', - 'You are not allowed to show this report.'=>'你没有显示此比赛的权限。', - 'You are not allowed to hide this report.'=>'你没有隐藏此比赛的权限。', - 'You are not allowed to remove this report.'=>'你没有删除此比赛的权限。', - 'Permission added successfully.'=>'权限添加成功。', - 'You are not allowed to add permissions.'=>'你没有添加权限的权限。', - 'Permission removed successfully.'=>'权限删除成功。', - 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', - 'Variable removed successfully.'=>'变量删除成功。', - 'Variable set successfully.'=>'变量设置成功。', - - 'Data base directory %s does not exist.'=>'数据目录 %s 不存在。', - 'Problem %s already exists.'=>'题目 %s 已存在。', - 'Problem directory %s does not exist.'=>'题目目录 %s 不存在。', - 'Problem configuration file %s does not exist.'=>'题目配置文件 %s 不存在。', - 'Problem description file %s does not exist.'=>'题目描述文件 %s 不存在。', - 'Problem %s does not have a data directory at %s.'=>'题目 %s 在 %s 没有数据目录。', - 'Case input file %s is not found in %s.'=>'数据输入文件 %s 在 %s 没有找到。', - 'Case output file %s is not found in %s.'=>'数据输出文件 %s 在 %s 没有找到。', - 'Problem %s showed successfully.'=>'题目 %s 显示成功。', - 'Problem %s hidden successfully.'=>'题目 %s 隐藏成功。', - 'Problem %s refreshed successfully.'=>'题目 %s 刷新成功。', - 'Record %s rejudged.'=>'提交记录 %s 已重判。', - 'Record %s manually judged.'=>'提交记录 %s 已人工判定。', - 'Report %s showed successfully.'=>'比赛 %s 已成功显示。', - 'Report %s hidden successfully.'=>'比赛 %s 已成功隐藏。', - 'Report %s removed successfully.'=>'比赛 %s 已成功移除。', - 'User'=>'用户', - 'Record'=>'比赛记录', + //app/controllers/DashboardController.php + 'You are not allowed to view the dashboard.' => '你没有进入控制台的权限。', + 'Problem title is not specified in problem.conf'=>'题目名称在 problem.conf 中没有指出。', + 'Problem author is not specified in problem.conf'=>'题目作者在 problem.conf 中没有指出。', + 'Problem case count is not specified in problem.conf'=>'题目数据组数在 problem.conf 中没有指出。', + 'Problem case score is not specified in problem.conf'=>'题目各组数据分数在 problem.conf 中没有指出。', + 'Problem time limit is not specified in problem.conf'=>'题目时间限制在 problem.conf 中没有指出。', + 'Problem memory limit is not specified in problem.conf'=>'题目内存限制在 problem.conf 中没有指出。', + 'Problem secret-before time is not specified in problem.conf'=>'题目隐藏截止时间在 problem.conf 中没有指出。', + 'You are not allowed to manage problems.'=>'你没有管理题目的权限。', + 'All problems refreshed successfully.'=>'所有题目成功刷新。', + 'You are not allowed to rejudge records.'=>'你没有重判记录的权限。', + 'Score cannot be negative.'=>'分数不能为负。', + 'You are not allowed to create reports.'=>'你没有创建比赛的权限。', + 'Report created successfully.'=>'比赛创建成功。', + 'You are not allowed to show this report.'=>'你没有显示此比赛的权限。', + 'You are not allowed to hide this report.'=>'你没有隐藏此比赛的权限。', + 'You are not allowed to remove this report.'=>'你没有删除此比赛的权限。', + 'Permission added successfully.'=>'权限添加成功。', + 'You are not allowed to add permissions.'=>'你没有添加权限的权限。', + 'Permission removed successfully.'=>'权限删除成功。', + 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', + 'Variable removed successfully.'=>'变量删除成功。', + 'Variable set successfully.'=>'变量设置成功。', - //app/controllers/ProblemController.php - 'Problem is secret now.'=>'题目现在处于隐藏状态。', + 'Data base directory %s does not exist.'=>'数据目录 %s 不存在。', + 'Problem %s already exists.'=>'题目 %s 已存在。', + 'Problem directory %s does not exist.'=>'题目目录 %s 不存在。', + 'Problem configuration file %s does not exist.'=>'题目配置文件 %s 不存在。', + 'Problem description file %s does not exist.'=>'题目描述文件 %s 不存在。', + 'Problem %s does not have a data directory at %s.'=>'题目 %s 在 %s 没有数据目录。', + 'Case input file %s is not found in %s.'=>'数据输入文件 %s 在 %s 没有找到。', + 'Case output file %s is not found in %s.'=>'数据输出文件 %s 在 %s 没有找到。', + 'Problem %s showed successfully.'=>'题目 %s 显示成功。', + 'Problem %s hidden successfully.'=>'题目 %s 隐藏成功。', + 'Problem %s refreshed successfully.'=>'题目 %s 刷新成功。', + 'Record %s rejudged.'=>'提交记录 %s 已重判。', + 'Record %s manually judged.'=>'提交记录 %s 已人工判定。', + 'Report %s showed successfully.'=>'比赛 %s 已成功显示。', + 'Report %s hidden successfully.'=>'比赛 %s 已成功隐藏。', + 'Report %s removed successfully.'=>'比赛 %s 已成功移除。', + 'User'=>'用户', + 'Record'=>'比赛记录', - //app/controllers/RecordController.php - 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', + //app/controllers/ProblemController.php + 'Problem is secret now.'=>'题目现在处于隐藏状态。', - //app/controllers/ReportController.php - 'You are not allowed to view this report.'=>'你没有查看此比赛的权限。', - 'This contest is not registrable.'=>'比赛不可注册。', - 'Registered successfully.'=>'注册成功。', - 'Not allowed to ask question.'=>'不允许提问。', - 'Please choose a category.'=>'请选择一个分类。', - 'Question too short (minimum 10 bytes).'=>'问题过短 (最少 10 字节)。', - 'Question too long (maximum 500 bytes).'=>'问题过长 (最大 500 字节)。', - 'Question saved.'=>'问题已保存。', - 'Not allowed to answer question.'=>'没有回答问题的权限。', - 'Question answered.'=>'问题已回答。', - 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', - 'Visibility toggled.'=>'可见度已更改。', + //app/controllers/RecordController.php + 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', - //app/controllers/UserController.php - 'Logged in successfully.'=>'登录成功。', - 'Password mismatch.'=>'密码错误。', - 'Username is too short.'=>'用户名过短。', - 'Username is too long.'=>'用户名过长。', - 'Password is too short.'=>'密码过短。', - 'Username is illegal.'=>'用户名包含非法字符。', - 'User already exists.'=>'用户已存在。', - 'Registered successfully.'=>'注册成功。', - 'Logged out successfully.'=>'注销成功。', - 'Information updated successfully.'=>'信息更新成功。', - 'Old password is too short.'=>'旧密码过短。', - 'New password is too short.'=>'新密码过短。', - 'Repeat password mismatch.'=>'两次输入密码不相同。', - 'Old password mismatch.'=>'旧密码错误。', - 'Password updated successfully.'=>'密码更改成功。', - 'Invalid email address.'=>'邮箱地址无效。', - 'Invalid verification code.'=>'验证码无效。', - 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', - 'Email verification failed: '=>'邮箱验证失败: ', - - //app/controllers/SubmitController.php - 'Code cannot be empty.'=>'代码不能为空。', - 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', - - - //app/models/User.php - 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', - 'You are required to verify your email address before doing this action.'=>'请先验证你的邮箱地址。' - + //app/controllers/ReportController.php + 'You are not allowed to view this report.'=>'你没有查看此比赛的权限。', + 'This contest is not registrable.'=>'比赛不可注册。', + 'Registered successfully.'=>'注册成功。', + 'Not allowed to ask question.'=>'不允许提问。', + 'Please choose a category.'=>'请选择一个分类。', + 'Question too short (minimum 10 bytes).'=>'问题过短 (最少 10 字节)。', + 'Question too long (maximum 500 bytes).'=>'问题过长 (最大 500 字节)。', + 'Question saved.'=>'问题已保存。', + 'Not allowed to answer question.'=>'没有回答问题的权限。', + 'Question answered.'=>'问题已回答。', + 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', + 'Visibility toggled.'=>'可见度已更改。', + + //app/controllers/UserController.php + 'Logged in successfully.'=>'登录成功。', + 'Password mismatch.'=>'密码错误。', + 'Username is too short.'=>'用户名过短。', + 'Username is too long.'=>'用户名过长。', + 'Password is too short.'=>'密码过短。', + 'Username is illegal.'=>'用户名包含非法字符。', + 'User already exists.'=>'用户已存在。', + 'Registered successfully.'=>'注册成功。', + 'Logged out successfully.'=>'注销成功。', + 'Information updated successfully.'=>'信息更新成功。', + 'Old password is too short.'=>'旧密码过短。', + 'New password is too short.'=>'新密码过短。', + 'Repeat password mismatch.'=>'两次输入密码不相同。', + 'Old password mismatch.'=>'旧密码错误。', + 'Password updated successfully.'=>'密码更改成功。', + 'Invalid email address.'=>'邮箱地址无效。', + 'Invalid verification code.'=>'验证码无效。', + 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', + 'Email verification failed: '=>'邮箱验证失败: ', + + //app/controllers/SubmitController.php + 'Code cannot be empty.'=>'代码不能为空。', + 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', - ) + //app/models/User.php + 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', + 'You are required to verify your email address before doing this action.'=>'请先验证你的邮箱地址。' + + + ) ); $language = 'chinese'; // 这里先固定为 chinese,以后会修改成根据用户来决定语言 if (isset($translations[$language][$english])) { From dbaabbfe33ae4401bc08015a38c218b06bc6e128 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Mon, 22 Oct 2012 11:38:57 +0800 Subject: [PATCH 09/13] =?UTF-8?q?flourish=20=E5=89=A9=E4=BD=99fUnexpectedE?= =?UTF-8?q?xception=E6=B2=A1=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/DashboardController.php | 14 +++++++------- app/controllers/ProblemController.php | 2 +- app/controllers/RecordController.php | 2 +- app/controllers/ReportController.php | 10 +++++----- app/controllers/SubmitController.php | 2 +- app/controllers/UserController.php | 10 +++++----- app/translate.php | 11 ++++++++--- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 78917c3..6c8734e 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -214,7 +214,7 @@ public function manageProblem($id, $action) fMessaging::create('success', T('All problems refreshed successfully.')); } } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); } fURL::redirect(Util::getReferer()); } @@ -238,7 +238,7 @@ public function rejudge($id) $new_record->store(); fMessaging::create('success', T('Record %s rejudged.',$id)); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); } fURL::redirect(Util::getReferer()); } @@ -257,7 +257,7 @@ public function manjudge($id, $score) $record->store(); fMessaging::create('success', T('Record %s manually judged.',$id)); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); } fURL::redirect(Util::getReferer()); } @@ -278,7 +278,7 @@ public function createReport() $report->store(); fMessaging::create('success', T('Report created successfully.')); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); } fURL::redirect(Util::getReferer()); } @@ -312,7 +312,7 @@ public function manageReport($id, $action) } } } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); } fURL::redirect(Util::getReferer()); } @@ -342,7 +342,7 @@ public function managePermission($action) } } } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); } fURL::redirect(Util::getReferer()); } @@ -366,7 +366,7 @@ public function setVariable() fMessaging::create('success', T('Variable set successfully.')); } } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); } fURL::redirect(Util::getReferer()); } diff --git a/app/controllers/ProblemController.php b/app/controllers/ProblemController.php index 618f2c7..fd21d35 100644 --- a/app/controllers/ProblemController.php +++ b/app/controllers/ProblemController.php @@ -47,7 +47,7 @@ public function show($id) $this->nav_class = 'problems'; $this->render('problem/show'); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); fURL::redirect(Util::getReferer()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); diff --git a/app/controllers/RecordController.php b/app/controllers/RecordController.php index c8733b1..081240a 100644 --- a/app/controllers/RecordController.php +++ b/app/controllers/RecordController.php @@ -35,7 +35,7 @@ public function show($id) $this->nav_class = 'status'; $this->render('record/show'); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); fURL::redirect(Util::getReferer()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index beadf38..89f94b6 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -51,7 +51,7 @@ public function show($id) $this->nav_class = 'reports'; $this->render('report/show'); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); fURL::redirect(Util::getReferer()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); @@ -73,7 +73,7 @@ public function newRegistration($id) BoardCacheInvalidator::invalidateByReport($report); fMessaging::create('success', T('Registered successfully.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -112,7 +112,7 @@ public function newQuestion($id) $question->store(); fMessaging::create('success', T('Question saved.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -132,7 +132,7 @@ public function replyQuestion($id) $question->store(); fMessaging::create('success', T('Question answered.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -151,7 +151,7 @@ public function toggleQuestionVisibility($id) $question->store(); fMessaging::create('success', T('Visibility toggled.')); } catch (fExpectedException $e) { - fMessaging::create('warning', $e->getMessage()); + fMessaging::create('warning', T($e->getMessage())); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } diff --git a/app/controllers/SubmitController.php b/app/controllers/SubmitController.php index b865d52..ceea9d5 100644 --- a/app/controllers/SubmitController.php +++ b/app/controllers/SubmitController.php @@ -48,7 +48,7 @@ public function submit($problem_id) Util::redirect('/status'); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); fMessaging::create('code', '/submit', fRequest::get('code', 'string')); Util::redirect("/submit?problem={$problem_id}"); } diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index a508231..145729b 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -78,7 +78,7 @@ public function login() } } } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); fURL::redirect(fAuthorization::getRequestedURL(TRUE, Util::getReferer())); } } @@ -121,7 +121,7 @@ public function updateInfo() fMessaging::create('success', T('Information updated successfully.')); fURL::redirect(Util::getReferer()); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); Util::redirect('/change/info'); } } @@ -158,7 +158,7 @@ public function updatePassword() fMessaging::create('success', T('Password updated successfully.')); fURL::redirect(Util::getReferer()); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); Util::redirect('/change/password'); } } @@ -178,7 +178,7 @@ public function sendVericode() try { $email = fRequest::get('email', 'string'); if (filter_var($email, FILTER_VALIDATE_EMAIL) == FALSE) { - throw new fValidationException('Invalid email address.'); + throw new fValidationException(T('Invalid email address.')); } $v = new Vericode(); @@ -208,7 +208,7 @@ public function sendVericode() ); Util::redirect('/email/verify/sent'); } catch (fException $e) { - fMessaging::create('error', $e->getMessage()); + fMessaging::create('error', T($e->getMessage())); Util::redirect('/email/verify'); } } diff --git a/app/translate.php b/app/translate.php index c4a7cb4..04f94bc 100644 --- a/app/translate.php +++ b/app/translate.php @@ -61,7 +61,6 @@ function T($english) 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', 'Variable removed successfully.'=>'变量删除成功。', 'Variable set successfully.'=>'变量设置成功。', - 'Data base directory %s does not exist.'=>'数据目录 %s 不存在。', 'Problem %s already exists.'=>'题目 %s 已存在。', 'Problem directory %s does not exist.'=>'题目目录 %s 不存在。', @@ -78,11 +77,14 @@ function T($english) 'Report %s showed successfully.'=>'比赛 %s 已成功显示。', 'Report %s hidden successfully.'=>'比赛 %s 已成功隐藏。', 'Report %s removed successfully.'=>'比赛 %s 已成功移除。', - 'User'=>'用户', - 'Record'=>'比赛记录', + 'The Record requested could not be found'=>'提交记录不存在。', + 'The Report requested could not be found'=>'比赛不存在。', + 'The Permission requested could not be found'=>'权限不存在。', + 'The Variable requested could not be found'=>'变量不存在。', //app/controllers/ProblemController.php 'Problem is secret now.'=>'题目现在处于隐藏状态。', + 'The Problem requested could not be found'=>'题目不存在。', //app/controllers/RecordController.php 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', @@ -100,6 +102,7 @@ function T($english) 'Question answered.'=>'问题已回答。', 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', 'Visibility toggled.'=>'可见度已更改。', + 'The Question requested could not be found'=>'问题不存在。', //app/controllers/UserController.php 'Logged in successfully.'=>'登录成功。', @@ -121,10 +124,12 @@ function T($english) 'Invalid verification code.'=>'验证码无效。', 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', 'Email verification failed: '=>'邮箱验证失败: ', + 'The User requested could not be found'=>'用户不存在。', //app/controllers/SubmitController.php 'Code cannot be empty.'=>'代码不能为空。', 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', + 'Invalid language.'=>'无效语言。', //app/models/User.php 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', From 60e500ba3569bd55b05b1af79093d2230a9253a9 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Sun, 28 Oct 2012 02:01:07 +0800 Subject: [PATCH 10/13] fix average total score in report --- app/helpers/ReportGenerator.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/helpers/ReportGenerator.php b/app/helpers/ReportGenerator.php index 2a5f7ee..df6e1e7 100644 --- a/app/helpers/ReportGenerator.php +++ b/app/helpers/ReportGenerator.php @@ -76,20 +76,18 @@ private static function prepareReport($records, $problem_ids, $usernames, &$firs $score[$row_average][$col_score] = 0; } else { + $totalsum = 0; // this is the normal case, calculate average scores for ($prob_i = 0; $prob_i < $p_size; $prob_i++) { $sum = 0; for ($user_i = 0; $user_i < $row_average; $user_i++) { $sum += $score[$user_i][$prob_i]; } + $totalsum += $sum; $score[$row_average][$prob_i] = round($sum / ($u_size - 1)); } // calculate average total score - $sum = 0; - for ($user_i = 0; $user_i < $row_average; $user_i++) { - $sum += $score[$user_i][$col_score]; - } - $score[$row_average][$col_score] = round($sum / ($u_size - 1)); + $score[$row_average][$col_score] = round($totalsum / ($u_size - 1)); } } From 6e73e0ebbcbfee5c7fbbc47eaba4e3cebd9f754c Mon Sep 17 00:00:00 2001 From: sjtufs Date: Sun, 11 Nov 2012 00:33:56 +0800 Subject: [PATCH 11/13] =?UTF-8?q?Fixed=20#39=20:=20=E5=9C=A8=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E5=AE=8C=E6=88=90=E7=9A=84report=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E4=B8=8D=E8=BF=9B=E8=A1=8C=E8=87=AA=E5=8A=A8=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 还需要进行实验 --- app/views/report/show.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/report/show.php b/app/views/report/show.php index ae88dc3..7a7f474 100644 --- a/app/views/report/show.php +++ b/app/views/report/show.php @@ -163,7 +163,9 @@ report->getId(); -$meta_refresh = Variable::getInteger('status-refresh', 30); +if ($this->report->getElapsedRatio() < 100) { + $meta_refresh = Variable::getInteger('status-refresh', 30); +} if (fAuthorization::checkLoggedIn() and $this->report->isRunning()) { $javascripts = array('jquery.tablesorter.min', 'board', 'ts-alert'); } else { From 7bd63b186dfb4b7fa34073306e82ceb448a16642 Mon Sep 17 00:00:00 2001 From: sjtufs Date: Fri, 16 Nov 2012 22:37:44 +0800 Subject: [PATCH 12/13] =?UTF-8?q?Fixed=20#=2037=20:=20=E5=9C=A8=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=E4=B8=AD=E6=B7=BB=E5=8A=A0=E6=8F=90=E4=BA=A4=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/problem/show.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/problem/show.php b/app/views/problem/show.php index 03e536b..d973ab7 100644 --- a/app/views/problem/show.php +++ b/app/views/problem/show.php @@ -12,7 +12,12 @@ 提交此题 + Date: Tue, 25 Dec 2012 17:34:36 +0800 Subject: [PATCH 13/13] modify login/register button --- app/controllers/DashboardController.php | 96 +++++++++--------- app/controllers/ProblemController.php | 4 +- app/controllers/RecordController.php | 4 +- app/controllers/ReportController.php | 34 +++---- app/controllers/SubmitController.php | 6 +- app/controllers/UserController.php | 46 ++++----- app/helpers/ReportGenerator.php | 5 - app/models/User.php | 4 +- app/translate.php | 127 ------------------------ app/views/layout/header.php | 14 +-- app/views/problem/show.php | 7 +- app/views/user/login.php | 4 +- 12 files changed, 107 insertions(+), 244 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 6c8734e..6c587b7 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -4,7 +4,7 @@ class DashboardController extends ApplicationController public function index() { if (!User::can('manage-site')) { - fMessaging::create('error', T('You are not allowed to view the dashboard.')); + fMessaging::create('error', 'You are not allowed to view the dashboard.'); fURL::redirect(Util::getReferer()); } @@ -44,7 +44,7 @@ private function gitPullOriginMaster() { $data_base_dir = Variable::getString('data-base-path'); if (!is_dir($data_base_dir)) { - throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); + throw new fValidationException("Data base directory {$data_base_dir} does not exist."); } $pwd = getcwd(); chdir($data_base_dir); @@ -61,7 +61,7 @@ private function showProblem($id, $ignore_git=FALSE) try { $problem = new Problem($id); if ($problem->exists()) { - throw new fValidationException(T('Problem %s already exists.'),$id); + throw new fValidationException("Problem {$id} already exists."); } } catch (fNotFoundException $e) { // fall through @@ -69,7 +69,7 @@ private function showProblem($id, $ignore_git=FALSE) $data_base_dir = Variable::getString('data-base-path'); if (!is_dir($data_base_dir)) { - throw new fValidationException(T('Data base directory %s does not exist.'),$data_base_dir); + throw new fValidationException("Data base directory {$data_base_dir} does not exist."); } if (!$ignore_git) { @@ -78,47 +78,47 @@ private function showProblem($id, $ignore_git=FALSE) $problem_dir = "{$data_base_dir}/problems/{$id}"; if (!is_dir($problem_dir)) { - throw new fValidationException(T('Problem directory %s does not exist.'),$problem_dir); + throw new fValidationException("Problem directory {$problem_dir} does not exist."); } $problem_conf = "{$problem_dir}/problem.conf"; if (!is_file($problem_conf)) { - throw new fValidationException(T('Problem configuration file %s does not exist.'),$problem_conf); + throw new fValidationException("Problem configuration file {$problem_conf} does not exist."); } $problem_text = "{$problem_dir}/problem.text"; if (!is_file($problem_text)) { - throw new fValidationException(T('Problem description file %s does not exist.'),$problem_text); + throw new fValidationException("Problem description file {$problem_text} does not exist."); } $data_dir = "{$problem_dir}/data"; if (!is_dir($data_dir)) { - throw new fValidationException(T('Problem %s does not have a data directory at %s.'),$id,$data_dir); + throw new fValidationException("Problem {$id} does not have a data directory at {$data_dir}"); } $properties_content = file_get_contents($problem_conf); $ini_content = str_replace(': ', ' = ', $properties_content); $ini = parse_ini_string($ini_content); if (!array_key_exists('title', $ini) or empty($ini['title'])) { - throw new fValidationException(T('Problem title is not specified in problem.conf')); + throw new fValidationException('Problem title is not specified in problem.conf'); } if (!array_key_exists('author', $ini)) { - throw new fValidationException(T('Problem author is not specified in problem.conf')); + throw new fValidationException('Problem author is not specified in problem.conf'); } if (!array_key_exists('case_count', $ini) or empty($ini['case_count'])) { - throw new fValidationException(T('Problem case count is not specified in problem.conf')); + throw new fValidationException('Problem case count is not specified in problem.conf'); } if (!array_key_exists('case_score', $ini) or empty($ini['case_score'])) { - throw new fValidationException(T('Problem case score is not specified in problem.conf')); + throw new fValidationException('Problem case score is not specified in problem.conf'); } if (!array_key_exists('time_limit', $ini) or empty($ini['time_limit'])) { - throw new fValidationException(T('Problem time limit is not specified in problem.conf')); + throw new fValidationException('Problem time limit is not specified in problem.conf'); } if (!array_key_exists('memory_limit', $ini) or empty($ini['memory_limit'])) { - throw new fValidationException(T('Problem memory limit is not specified in problem.conf')); + throw new fValidationException('Problem memory limit is not specified in problem.conf'); } if (!array_key_exists('secret_before', $ini) or empty($ini['secret_before'])) { - throw new fValidationException(T('Problem secret-before time is not specified in problem.conf')); + throw new fValidationException('Problem secret-before time is not specified in problem.conf'); } if (empty($ini['author'])) { @@ -140,11 +140,11 @@ private function showProblem($id, $ignore_git=FALSE) for ($t = 1; $t <= $problem->getCaseCount(); $t++) { $input = "{$data_dir}/$t.in"; if (!is_file($input)) { - throw new fValidationException(T('Case input file %s is not found in %s.'),$input,$data_dir); + throw new fValidationException("Case input file {$input} is not found in {$data_dir}"); } $output = "{$data_dir}/$t.out"; if (!is_file($output)) { - throw new fValidationException(T('Case out file %s is not found in %s.'),$output,$data_dir); + throw new fValidationException("Case output file {$output} is not found in {$data_dir}"); } } @@ -198,23 +198,23 @@ public function manageProblem($id, $action) { try { if (!User::can('manage-site')) { - throw new fAuthorizationException(T('You are not allowed to manage problems.')); + throw new fAuthorizationException('You are not allowed to manage problems.'); } if ($action == 'Show') { $this->showProblem($id); - fMessaging::create('success', T('Problem %s showed successfully.',$id)); + fMessaging::create('success', "Problem {$id} showed successfully."); } else if ($action == 'Hide') { $this->hideProblem($id); - fMessaging::create('success', T('Problem %s hidden successfully.',$id)); + fMessaging::create('success', "Problem {$id} hidden successfully."); } else if ($action == 'Refresh') { $this->refreshProblem($id); - fMessaging::create('success', T('Problem %s refreshed successfully.',$id)); + fMessaging::create('success', "Problem {$id} refreshed successfully."); } else if ($action == 'Refresh All' and User::can('refresh-all')) { $this->refreshAllProblems(); - fMessaging::create('success', T('All problems refreshed successfully.')); + fMessaging::create('success', 'All problems refreshed successfully.'); } } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); } fURL::redirect(Util::getReferer()); } @@ -223,7 +223,7 @@ public function rejudge($id) { try { if (!User::can('rejudge-record')) { - throw new fAuthorizationException(T('You are not allowed to rejudge records.')); + throw new fAuthorizationException('You are not allowed to rejudge records.'); } $old_record = new Record($id); $new_record = new Record(); @@ -236,9 +236,9 @@ public function rejudge($id) $new_record->setJudgeMessage('Rejudging... PROB=' . $old_record->getProblemId() . ' LANG=' . $old_record->getLanguageName()); $new_record->setVerdict(Verdict::UNKNOWN); $new_record->store(); - fMessaging::create('success', T('Record %s rejudged.',$id)); + fMessaging::create('success', "Record {$id} rejudged."); } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); } fURL::redirect(Util::getReferer()); } @@ -247,17 +247,17 @@ public function manjudge($id, $score) { try { if (!User::can('rejudge-record')) { - throw new fAuthorizationException(T('You are not allowed to rejudge records.')); + throw new fAuthorizationException('You are not allowed to rejudge records.'); } if ($score < 0) { - throw new fValidationException(T('Score cannot be negative.')); + throw new fValidationException('Score cannot be negative.'); } $record = new Record($id); $record->manjudge($score); $record->store(); - fMessaging::create('success', T('Record %s manually judged.',$id)); + fMessaging::create('success', "Record {$id} manually judged."); } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); } fURL::redirect(Util::getReferer()); } @@ -266,7 +266,7 @@ public function createReport() { try { if (!User::can('create-report')) { - throw new fAuthorizationException(T('You are not allowed to create reports.')); + throw new fAuthorizationException('You are not allowed to create reports.'); } $report = new Report(); $report->setVisible(fRequest::get('visible', 'integer')); @@ -276,9 +276,9 @@ public function createReport() $report->setStartDatetime(fRequest::get('start_time', 'timestamp')); $report->setEndDatetime(fRequest::get('end_time', 'timestamp')); $report->store(); - fMessaging::create('success', T('Report created successfully.')); + fMessaging::create('success', 'Report created successfully.'); } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); } fURL::redirect(Util::getReferer()); } @@ -291,28 +291,28 @@ public function manageReport($id, $action) if (User::can('view-any-report')) { $report->setVisible(1); $report->store(); - fMessaging::create('success', T('Report %s showed successfully.',$id)); + fMessaging::create('success', "Report {$id} showed successfully."); } else { - throw new fAuthorizationException(T('You are not allowed to show this report.')); + throw new fAuthorizationException('You are not allowed to show this report.'); } } else if ($action == 'Hide') { if (User::can('view-any-report')) { $report->setVisible(0); $report->store(); - fMessaging::create('success', T('Report %s hidden successfully.',$id)); + fMessaging::create('success', "Report {$id} hidden successfully."); } else { - throw new fAuthorizationException(T('You are not allowed to hide this report.')); + throw new fAuthorizationException('You are not allowed to hide this report.'); } } else if ($action == 'Remove') { if (User::can('remove-report')) { $report->delete(); - fMessaging::create('success', T('Report %s removed successfully.',$id)); + fMessaging::create('success', "Report {$id} removed successfully."); } else { - throw new fAuthorizationException(T('You are not allowed to remove this report.')); + throw new fAuthorizationException('You are not allowed to remove this report.'); } } } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); } fURL::redirect(Util::getReferer()); } @@ -328,21 +328,21 @@ public function managePermission($action) $permission->setUserName($user_name); $permission->setPermissionName($permission_name); $permission->store(); - fMessaging::create('success', T('Permission added successfully.')); + fMessaging::create('success', 'Permission added successfully.'); } else { - throw new fAuthorizationException(T('You are not allowed to add permissions.')); + throw new fAuthorizationException('You are not allowed to add permissions.'); } } else if ($action == 'Remove') { if (User::can('remove-permission')) { $permission = new Permission(array('user_name' => $user_name, 'permission_name' => $permission_name)); $permission->delete(); - fMessaging::create('success', T('Permission removed successfully.')); + fMessaging::create('success', 'Permission removed successfully.'); } else { - throw new fAuthorizationException(T('You are not allowed to remove permissions.')); + throw new fAuthorizationException('You are not allowed to remove permissions.'); } } } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); } fURL::redirect(Util::getReferer()); } @@ -353,7 +353,7 @@ public function setVariable() if (fRequest::get('remove', 'boolean')) { $variable = new Variable(fRequest::get('name')); $variable->delete(); - fMessaging::create('success', T('Variable removed successfully.')); + fMessaging::create('success', 'Variable removed successfully.'); } else { try { $variable = new Variable(fRequest::get('name')); @@ -363,10 +363,10 @@ public function setVariable() } $variable->setValue(fRequest::get('value')); $variable->store(); - fMessaging::create('success', T('Variable set successfully.')); + fMessaging::create('success', 'Variable set successfully.'); } } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); } fURL::redirect(Util::getReferer()); } diff --git a/app/controllers/ProblemController.php b/app/controllers/ProblemController.php index fd21d35..7a07da9 100644 --- a/app/controllers/ProblemController.php +++ b/app/controllers/ProblemController.php @@ -41,13 +41,13 @@ public function show($id) $this->problem = new Problem($id); if ($this->problem->isSecretNow()) { if (!User::can('view-any-problem')) { - throw new fAuthorizationException(T('Problem is secret now.')); + throw new fAuthorizationException('Problem is secret now.'); } } $this->nav_class = 'problems'; $this->render('problem/show'); } catch (fExpectedException $e) { - fMessaging::create('warning', T($e->getMessage())); + fMessaging::create('warning', $e->getMessage()); fURL::redirect(Util::getReferer()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); diff --git a/app/controllers/RecordController.php b/app/controllers/RecordController.php index 081240a..39f6c8e 100644 --- a/app/controllers/RecordController.php +++ b/app/controllers/RecordController.php @@ -30,12 +30,12 @@ public function show($id) try { $this->record = new Record($id); if (!$this->record->isReadable()) { - throw new fAuthorizationException(T('You are not allowed to read this record.')); + throw new fAuthorizationException('You are not allowed to read this record.'); } $this->nav_class = 'status'; $this->render('record/show'); } catch (fExpectedException $e) { - fMessaging::create('warning', T($e->getMessage())); + fMessaging::create('warning', $e->getMessage()); fURL::redirect(Util::getReferer()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index 948b2e3..b717a8f 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -42,7 +42,7 @@ public function show($id) try { $this->report = new Report($id); if (!$this->report->isReadable()) { - throw new fAuthorizationException(T('You are not allowed to view this report.')); + throw new fAuthorizationException('You are not allowed to view this report.'); } global $cache; @@ -73,7 +73,7 @@ public function show($id) $this->render('report/show'); } catch (fExpectedException $e) { - fMessaging::create('warning', T($e->getMessage())); + fMessaging::create('warning', $e->getMessage()); fURL::redirect(Util::getReferer()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); @@ -86,16 +86,16 @@ public function newRegistration($id) try { $report = new Report($id); if (!$report->isRegistrable()) { - throw new fValidationException(T('This contest is not registrable.')); + throw new fValidationException('This contest is not registrable.'); } $registration = new Registration(); $registration->setUsername(fAuthorization::getUserToken()); $registration->setReportId($report->getId()); $registration->store(); BoardCacheInvalidator::invalidateByReport($report); - fMessaging::create('success', T('Registered successfully.')); + fMessaging::create('success', 'Registered successfully.'); } catch (fExpectedException $e) { - fMessaging::create('warning', T($e->getMessage())); + fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -107,11 +107,11 @@ public function newQuestion($id) try { $report = new Report($id); if (!$report->allowQuestion()) { - throw new fValidationException(T('Not allowed to ask question.')); + throw new fValidationException('Not allowed to ask question.'); } $category = fRequest::get('category', 'integer'); if ($category == 0) { - throw new fValidationException(T('Please choose a category.')); + throw new fValidationException('Please choose a category.'); } $question = new Question(); $question->setUsername(fAuthorization::getUserToken()); @@ -126,15 +126,15 @@ public function newQuestion($id) $question->setAskTime(new fTimestamp()); $question->setQuestion(trim(fRequest::get('question'))); if (strlen($question->getQuestion()) < 10) { - throw new fValidationException(T('Question too short (minimum 10 bytes).')); + throw new fValidationException('Question too short (minimum 10 bytes).'); } if (strlen($question->getQuestion()) > 500) { - throw new fValidationException(T('Question too long (maximum 500 bytes).')); + throw new fValidationException('Question too long (maximum 500 bytes).'); } $question->store(); - fMessaging::create('success', T('Question saved.')); + fMessaging::create('success', 'Question saved.'); } catch (fExpectedException $e) { - fMessaging::create('warning', T($e->getMessage())); + fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -147,14 +147,14 @@ public function replyQuestion($id) $question = new Question($id); $report = new Report($report_id = $question->getReportId()); if (!$report->allowAnswer()) { - throw new fValidationException(T('Not allowed to answer question.')); + throw new fValidationException('Not allowed to answer question.'); } $question->setAnswerTime(new fTimestamp()); $question->setAnswer(trim(fRequest::get('reply'))); $question->store(); - fMessaging::create('success', T('Question answered.')); + fMessaging::create('success', 'Question answered.'); } catch (fExpectedException $e) { - fMessaging::create('warning', T($e->getMessage())); + fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } @@ -167,13 +167,13 @@ public function toggleQuestionVisibility($id) $question = new Question($id); $report = new Report($report_id = $question->getReportId()); if (!$report->allowAnswer()) { - throw new fValidationException(T('Not allowed to toggle question visibility.')); + throw new fValidationException('Not allowed to toggle question visibility.'); } $question->setCategory(-$question->getCategory()); $question->store(); - fMessaging::create('success', T('Visibility toggled.')); + fMessaging::create('success', 'Visibility toggled.'); } catch (fExpectedException $e) { - fMessaging::create('warning', T($e->getMessage())); + fMessaging::create('warning', $e->getMessage()); } catch (fUnexpectedException $e) { fMessaging::create('error', $e->getMessage()); } diff --git a/app/controllers/SubmitController.php b/app/controllers/SubmitController.php index ceea9d5..e7ab59f 100644 --- a/app/controllers/SubmitController.php +++ b/app/controllers/SubmitController.php @@ -27,11 +27,11 @@ public function submit($problem_id) fSession::set('last_language', $language); $code = trim(fRequest::get('code', 'string')); if (strlen($code) == 0) { - throw new fValidationException(T('Code cannot be empty.')); + throw new fValidationException('Code cannot be empty.'); } if ($problem->isSecretNow()) { if (!User::can('view-any-problem')) { - throw new fAuthorizationException(T('Problem is secret now. You are not allowed to submit this problem.')); + throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.'); } } @@ -48,7 +48,7 @@ public function submit($problem_id) Util::redirect('/status'); } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); fMessaging::create('code', '/submit', fRequest::get('code', 'string')); Util::redirect("/submit?problem={$problem_id}"); } diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 145729b..695ce03 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -46,39 +46,39 @@ public function login() $user = new User($username); if ($user->getPassword() == $password_hash) { fAuthorization::setUserToken($user->getUsername()); - fMessaging::create('success', T('Logged in successfully.')); + fMessaging::create('success', 'Logged in successfully.'); fURL::redirect(fAuthorization::getRequestedURL(TRUE, Util::getReferer())); } else { - throw new fValidationException(T('Password mismatch.')); + throw new fValidationException('Password mismatch.'); } } else if (fRequest::get('action') == '注册') { if (strlen($username) < 4) { - throw new fValidationException(T('Username is too short.')); + throw new fValidationException('Username is too short.'); } if (strlen($username) > 20) { - throw new fValidationException(T('Username is too long.')); + throw new fValidationException('Username is too long.'); } if (strlen($password) < 6) { - throw new fValidationException(T('Password is too short.')); + throw new fValidationException('Password is too short.'); } if (Util::contains('`~!@#$%^&*()-+=[]\\;\',/{}|:"<>?', $username) or preg_match('/\s/', $username)) { - throw new fValidationException(T('Username is illegal.')); + throw new fValidationException('Username is illegal.'); } try { $user = new User($username); - throw new fValidationException(T('User already exists.')); + throw new fValidationException('User already exists.'); } catch (fNotFoundException $e) { $user = new User(); $user->setUsername($username); $user->setPassword($password_hash); $user->store(); fAuthorization::setUserToken($user->getUsername()); - fMessaging::create('success', T('Registered successfully.')); + fMessaging::create('success', 'Registered successfully.'); Util::redirect('/email/verify'); } } } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); fURL::redirect(fAuthorization::getRequestedURL(TRUE, Util::getReferer())); } } @@ -86,7 +86,7 @@ public function login() public function logout() { fAuthorization::destroyUserInfo(); - fMessaging::create('success', T('Logged out successfully.')); + fMessaging::create('success', 'Logged out successfully.'); if (strstr(Util::getReferer(), 'contest')) { fURL::redirect(SITE_BASE); } else { @@ -118,10 +118,10 @@ public function updateInfo() $profile->setPhoneNumber($phone_number); $profile->store(); - fMessaging::create('success', T('Information updated successfully.')); + fMessaging::create('success', 'Information updated successfully.'); fURL::redirect(Util::getReferer()); } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); Util::redirect('/change/info'); } } @@ -139,26 +139,26 @@ public function updatePassword() $new_password = fRequest::get('new_password'); $repeat_password = fRequest::get('repeat_password'); if (strlen($old_password) < 6) { - throw new fValidationException(T('Old password is too short.')); + throw new fValidationException('Old password is too short.'); } if (strlen($new_password) < 6) { - throw new fValidationException(T('New password is too short.')); + throw new fValidationException('New password is too short.'); } if ($new_password != $repeat_password) { - throw new fValidationException(T('Repeat password mismatch.')); + throw new fValidationException('Repeat password mismatch.'); } $user = new User(fAuthorization::getUserToken()); $old_password_hash = static::hashPassword($old_password); if ($user->getPassword() != $old_password_hash) { - throw new fValidationException(T('Old password mismatch.')); + throw new fValidationException('Old password mismatch.'); } $new_password_hash = static::hashPassword($new_password); $user->setPassword($new_password_hash); $user->store(); - fMessaging::create('success', T('Password updated successfully.')); + fMessaging::create('success', 'Password updated successfully.'); fURL::redirect(Util::getReferer()); } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); Util::redirect('/change/password'); } } @@ -178,7 +178,7 @@ public function sendVericode() try { $email = fRequest::get('email', 'string'); if (filter_var($email, FILTER_VALIDATE_EMAIL) == FALSE) { - throw new fValidationException(T('Invalid email address.')); + throw new fValidationException('Invalid email address.'); } $v = new Vericode(); @@ -208,7 +208,7 @@ public function sendVericode() ); Util::redirect('/email/verify/sent'); } catch (fException $e) { - fMessaging::create('error', T($e->getMessage())); + fMessaging::create('error', $e->getMessage()); Util::redirect('/email/verify'); } } @@ -224,7 +224,7 @@ public function checkVericode($id, $vericode) try { $v = new Vericode($id); if ($v->getUsername() != fAuthorization::getUserToken() or $v->getVericode() != $vericode) { - throw new fValidationException(T('Invalid verification code.')); + throw new fValidationException('Invalid verification code.'); } $ue = new UserEmail(); @@ -232,12 +232,12 @@ public function checkVericode($id, $vericode) $ue->setEmail($v->getEmail()); $ue->store(); - fMessaging::create('success', T('Your email address is verified successfully.')); + fMessaging::create('success', 'Your email address is verified successfully.'); $referer = fMessaging::retrieve('referer', SITE_BASE . '/email/verify'); if ($referer == NULL) $referer = SITE_BASE; fURL::redirect($referer); } catch (fException $e) { - fMessaging::create('error', T('Email verification failed: ') . $e->getMessage()); + fMessaging::create('error', 'Email verification failed: ' . $e->getMessage()); Util::redirect('/email/verify'); } } diff --git a/app/helpers/ReportGenerator.php b/app/helpers/ReportGenerator.php index ac03cd2..662bf8a 100644 --- a/app/helpers/ReportGenerator.php +++ b/app/helpers/ReportGenerator.php @@ -76,7 +76,6 @@ private static function prepareReport($records, $problem_ids, $usernames, &$firs $score[$row_average][$col_score] = 0; } else { - $totalsum = 0; // this is the normal case, calculate average scores $totalsum = 0; for ($prob_i = 0; $prob_i < $p_size; $prob_i++) { @@ -87,11 +86,7 @@ private static function prepareReport($records, $problem_ids, $usernames, &$firs $totalsum += $sum; $score[$row_average][$prob_i] = round($sum / ($u_size - 1)); } -<<<<<<< HEAD - // calculate average total score -======= // calculate average total score ->>>>>>> upstream/master $score[$row_average][$col_score] = round($totalsum / ($u_size - 1)); } } diff --git a/app/models/User.php b/app/models/User.php index 0adeb4f..d9bd256 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -44,7 +44,7 @@ public static function getVerifiedEmail($username=NULL) } $email = UserEmail::fetch($username); if ($email === NULL) { - return T('Click here to verify your email address.'); + return '点击此处进行邮件验证'; } return $email; } @@ -65,7 +65,7 @@ public static function requireEmailVerified() { if (!fAuthorization::checkLoggedIn()) return; if (User::hasEmailVerified()) return; - fMessaging::create('warning', T('You are required to verify your email address before doing this action.')); + fMessaging::create('warning', 'You are required to verify your email address before doing this action.'); Util::redirect('/email/verify'); } } diff --git a/app/translate.php b/app/translate.php index 04f94bc..af0bcaf 100644 --- a/app/translate.php +++ b/app/translate.php @@ -30,130 +30,3 @@ function translate($string) } return $string; } - -function T($english) -{ - $numargs=func_num_args(); - static $translations = array( - 'chinese' => array( - - //app/controllers/DashboardController.php - 'You are not allowed to view the dashboard.' => '你没有进入控制台的权限。', - 'Problem title is not specified in problem.conf'=>'题目名称在 problem.conf 中没有指出。', - 'Problem author is not specified in problem.conf'=>'题目作者在 problem.conf 中没有指出。', - 'Problem case count is not specified in problem.conf'=>'题目数据组数在 problem.conf 中没有指出。', - 'Problem case score is not specified in problem.conf'=>'题目各组数据分数在 problem.conf 中没有指出。', - 'Problem time limit is not specified in problem.conf'=>'题目时间限制在 problem.conf 中没有指出。', - 'Problem memory limit is not specified in problem.conf'=>'题目内存限制在 problem.conf 中没有指出。', - 'Problem secret-before time is not specified in problem.conf'=>'题目隐藏截止时间在 problem.conf 中没有指出。', - 'You are not allowed to manage problems.'=>'你没有管理题目的权限。', - 'All problems refreshed successfully.'=>'所有题目成功刷新。', - 'You are not allowed to rejudge records.'=>'你没有重判记录的权限。', - 'Score cannot be negative.'=>'分数不能为负。', - 'You are not allowed to create reports.'=>'你没有创建比赛的权限。', - 'Report created successfully.'=>'比赛创建成功。', - 'You are not allowed to show this report.'=>'你没有显示此比赛的权限。', - 'You are not allowed to hide this report.'=>'你没有隐藏此比赛的权限。', - 'You are not allowed to remove this report.'=>'你没有删除此比赛的权限。', - 'Permission added successfully.'=>'权限添加成功。', - 'You are not allowed to add permissions.'=>'你没有添加权限的权限。', - 'Permission removed successfully.'=>'权限删除成功。', - 'You are not allowed to remove permissions.'=>'你没有删除权限的权限。', - 'Variable removed successfully.'=>'变量删除成功。', - 'Variable set successfully.'=>'变量设置成功。', - 'Data base directory %s does not exist.'=>'数据目录 %s 不存在。', - 'Problem %s already exists.'=>'题目 %s 已存在。', - 'Problem directory %s does not exist.'=>'题目目录 %s 不存在。', - 'Problem configuration file %s does not exist.'=>'题目配置文件 %s 不存在。', - 'Problem description file %s does not exist.'=>'题目描述文件 %s 不存在。', - 'Problem %s does not have a data directory at %s.'=>'题目 %s 在 %s 没有数据目录。', - 'Case input file %s is not found in %s.'=>'数据输入文件 %s 在 %s 没有找到。', - 'Case output file %s is not found in %s.'=>'数据输出文件 %s 在 %s 没有找到。', - 'Problem %s showed successfully.'=>'题目 %s 显示成功。', - 'Problem %s hidden successfully.'=>'题目 %s 隐藏成功。', - 'Problem %s refreshed successfully.'=>'题目 %s 刷新成功。', - 'Record %s rejudged.'=>'提交记录 %s 已重判。', - 'Record %s manually judged.'=>'提交记录 %s 已人工判定。', - 'Report %s showed successfully.'=>'比赛 %s 已成功显示。', - 'Report %s hidden successfully.'=>'比赛 %s 已成功隐藏。', - 'Report %s removed successfully.'=>'比赛 %s 已成功移除。', - 'The Record requested could not be found'=>'提交记录不存在。', - 'The Report requested could not be found'=>'比赛不存在。', - 'The Permission requested could not be found'=>'权限不存在。', - 'The Variable requested could not be found'=>'变量不存在。', - - //app/controllers/ProblemController.php - 'Problem is secret now.'=>'题目现在处于隐藏状态。', - 'The Problem requested could not be found'=>'题目不存在。', - - //app/controllers/RecordController.php - 'You are not allowed to read this record.'=>'你没有查看此记录的权限。', - - //app/controllers/ReportController.php - 'You are not allowed to view this report.'=>'你没有查看此比赛的权限。', - 'This contest is not registrable.'=>'比赛不可注册。', - 'Registered successfully.'=>'注册成功。', - 'Not allowed to ask question.'=>'不允许提问。', - 'Please choose a category.'=>'请选择一个分类。', - 'Question too short (minimum 10 bytes).'=>'问题过短 (最少 10 字节)。', - 'Question too long (maximum 500 bytes).'=>'问题过长 (最大 500 字节)。', - 'Question saved.'=>'问题已保存。', - 'Not allowed to answer question.'=>'没有回答问题的权限。', - 'Question answered.'=>'问题已回答。', - 'Not allowed to toggle question visibility.'=>'没有更改此问题可见度的权限。', - 'Visibility toggled.'=>'可见度已更改。', - 'The Question requested could not be found'=>'问题不存在。', - - //app/controllers/UserController.php - 'Logged in successfully.'=>'登录成功。', - 'Password mismatch.'=>'密码错误。', - 'Username is too short.'=>'用户名过短。', - 'Username is too long.'=>'用户名过长。', - 'Password is too short.'=>'密码过短。', - 'Username is illegal.'=>'用户名包含非法字符。', - 'User already exists.'=>'用户已存在。', - 'Registered successfully.'=>'注册成功。', - 'Logged out successfully.'=>'注销成功。', - 'Information updated successfully.'=>'信息更新成功。', - 'Old password is too short.'=>'旧密码过短。', - 'New password is too short.'=>'新密码过短。', - 'Repeat password mismatch.'=>'两次输入密码不相同。', - 'Old password mismatch.'=>'旧密码错误。', - 'Password updated successfully.'=>'密码更改成功。', - 'Invalid email address.'=>'邮箱地址无效。', - 'Invalid verification code.'=>'验证码无效。', - 'Your email address is verified successfully.'=>'你的邮箱已成功验证。', - 'Email verification failed: '=>'邮箱验证失败: ', - 'The User requested could not be found'=>'用户不存在。', - - //app/controllers/SubmitController.php - 'Code cannot be empty.'=>'代码不能为空。', - 'Problem is secret now. You are not allowed to submit this problem.'=>'题目现在处于隐藏状态,不能提交此题目。', - 'Invalid language.'=>'无效语言。', - - //app/models/User.php - 'Click here to verify your email address.'=>'点击此处验证你的邮箱地址。', - 'You are required to verify your email address before doing this action.'=>'请先验证你的邮箱地址。' - - - ) - ); - $language = 'chinese'; // 这里先固定为 chinese,以后会修改成根据用户来决定语言 - if (isset($translations[$language][$english])) { - if($numargs==2){ - $arg2=func_get_arg(1); - $t=$translations[$language][$english]; - $translation=sprintf("$t",$arg2); - return $translation; - } - if($numargs==3){ - $arg2=func_get_arg(1); - $arg3=func_get_arg(2); - $t=$translations[$language][$english]; - $translation=sprintf("$t",$arg2,$arg3); - return $translation; - } - return $translations[$language][$english]; - } - return $english; -} diff --git a/app/views/layout/header.php b/app/views/layout/header.php index f6846af..4dd1596 100644 --- a/app/views/layout/header.php +++ b/app/views/layout/header.php @@ -8,7 +8,7 @@ - + @@ -55,8 +55,8 @@
- 注册 +
-
- - + +