Skip to content

Commit

Permalink
improve exam trans
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Jun 26, 2024
1 parent b0fb051 commit 285e106
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Filament\Resources\User\ExamUserResource\Pages;

use App\Filament\Resources\User\ExamUserResource;
use App\Models\Exam;
use App\Repositories\ExamRepository;
use Carbon\Carbon;
use Filament\Pages\Actions;
Expand Down Expand Up @@ -62,8 +63,12 @@ private function getDetailCardData(): array

protected function getViewData(): array
{
/** @var Exam $exam */
$exam = $this->record->exam;
return [
'cardData' => $this->getDetailCardData(),
'result_pass_trans_key' => $exam->getPassResultTransKey('pass'),
'result_not_pass_trans_key' => $exam->getPassResultTransKey('not_pass'),
];
}

Expand Down
9 changes: 9 additions & 0 deletions app/Models/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ public function getMessageContentTransKey(string $result): string
};
}

public function getPassResultTransKey(string $result): string
{
return match ($this->type) {
self::TYPE_EXAM => "exam.result_{$result}_for_exam",
self::TYPE_TASK => "exam.result_{$result}_for_task",
default => throw new \RuntimeException("Invalid type: " . $this->type)
};
}

public function isTypeExam(): bool
{
return $this->type == self::TYPE_EXAM;
Expand Down
2 changes: 1 addition & 1 deletion include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-06-24');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-06-27');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down
3 changes: 2 additions & 1 deletion nexus/Exam/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function render($uid)
if (empty($userExam)) {
return '';
}
/** @var \App\Models\Exam $exam */
$exam = $userExam->exam;
$row = [];
$row[] = sprintf('%s:%s', nexus_trans('exam.name'), $exam->name);
Expand All @@ -26,7 +27,7 @@ public function render($uid)
nexus_trans('exam.require_value'), $index['require_value_formatted'],
nexus_trans('exam.current_value'), $index['current_value_formatted'],
nexus_trans('exam.result'),
$index['passed'] ? nexus_trans('exam.result_pass') : nexus_trans('exam.result_not_pass')
$index['passed'] ? nexus_trans($exam->getPassResultTransKey("pass")) : nexus_trans($exam->getPassResultTransKey("not_pass"))
);
}
}
Expand Down
21 changes: 15 additions & 6 deletions resources/lang/en/exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@
'require_value' => 'Require',
'current_value' => 'Current',
'result' => 'Result',
'result_pass' => 'Pass!',
'result_not_pass' => '<span style="color: red">Not pass!</span>',
'checkout_pass_message_subject' => 'Exam pass!',
'checkout_pass_message_content' => 'Congratulation! You have complete the exam: :exam_name in time(:begin ~ :end)',
'checkout_not_pass_message_subject' => 'Exam not pass, and account is banned!',
'checkout_not_pass_message_content' => 'You did not complete the exam: :exam_name in time(:begin ~ :end), and your account has be banned!',

'result_pass_for_exam' => 'Passed!',
'result_pass_for_task' => 'Completed!',
'result_not_pass_for_exam' => '<span style="color: red">Not Passed!</span>',
'result_not_pass_for_task' => '<span style="color: red">Not Completed!</span>',
'checkout_pass_message_subject_for_exam' => 'Exam passed!',
'checkout_pass_message_content_for_exam' => 'Congratulation! You have pass the exam: :exam_name in time(:begin ~ :end)',
'checkout_not_pass_message_subject_for_exam' => 'Exam not pass, and account is banned!',
'checkout_not_pass_message_content_for_exam' => 'You did not pass the exam: :exam_name in time(:begin ~ :end), and your account has be banned!',

'checkout_pass_message_subject_for_task' => 'Task completed!',
'checkout_pass_message_content_for_task' => 'Congratulation! You have complete the task: :exam_name in time(:begin ~ :end), got bonus: :success_reward_bonus',
'checkout_not_pass_message_subject_for_task' => 'Task not completed!',
'checkout_not_pass_message_content_for_task' => 'You dit not complete the task: :exam_name in time (:begin ~ :end), deduct bonus: :fail_deduct_bonus.',

'ban_log_reason' => 'Not complete exam: :exam_name in time(:begin ~ :end)',
'ban_user_modcomment' => 'Due to not complete exam: :exam_name(:begin ~ :end), ban by system.',
'admin' => [
Expand Down
21 changes: 15 additions & 6 deletions resources/lang/zh_TW/exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@
'require_value' => '要求',
'current_value' => '當前',
'result' => '結果',
'result_pass' => '通過!',
'result_not_pass' => '<span style="color: red">未通過!</span>',
'checkout_pass_message_subject' => '考核通過!',
'checkout_pass_message_content' => '恭喜!你在規定時間內(:begin ~ :end)順利完成了考核::exam_name。',
'checkout_not_pass_message_subject' => '考核未通過,賬號被禁用!',
'checkout_not_pass_message_content' => '你在規定時間內(:begin ~ :end)未完成考核::exam_name,賬號已被禁用。',

'result_pass_for_exam' => '通過!',
'result_pass_for_task' => '完成!',
'result_not_pass_for_exam' => '<span style="color: red">未通過!</span>',
'result_not_pass_for_task' => '<span style="color: red">未完成!</span>',
'checkout_pass_message_subject_for_exam' => '考核通過!',
'checkout_pass_message_content_for_exam' => '恭喜!你在規定時間內(:begin ~ :end)順利完成了考核::exam_name。',
'checkout_not_pass_message_subject_for_exam' => '考核未通過,賬號被禁用!',
'checkout_not_pass_message_content_for_exam' => '你在規定時間內(:begin ~ :end)未完成考核::exam_name,賬號已被禁用。',

'checkout_pass_message_subject_for_task' => '任務完成!',
'checkout_pass_message_content_for_task' => '恭喜!你在規定時間內(:begin ~ :end)順利完成了任務::exam_name,獲得獎勵魔力::success_reward_bonus',
'checkout_not_pass_message_subject_for_task' => '任務未完成!',
'checkout_not_pass_message_content_for_task' => '你在規定時間內(:begin ~ :end)未完成任務::exam_name,扣除魔力::fail_deduct_bonus。',

'ban_log_reason' => '未完成考核::exam_name(:begin ~ :end)',
'ban_user_modcomment' => '未完成考核: :exam_name(:begin ~ :end), 被系統禁用.',
'admin' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<td>{{ $index['index_formatted'] }}</td>
<td>{{ $index['require_value_formatted'] }}</td>
<td>{{ $index['current_value_formatted'] }}</td>
<td>{{ $index['passed'] ? __('admin.resources.exam_user.result_passed') : __('admin.resources.exam_user.result_not_passed') }}</td>
<td>{!! $index['passed'] ? __($result_pass_trans_key) : __($result_not_pass_trans_key) !!}</td>
</tr>
@endforeach
</tbody>
Expand Down

0 comments on commit 285e106

Please sign in to comment.