Skip to content

Commit 7f3f203

Browse files
RiedleroDCopilotmcquenji
authored
feat: Factored out strings into translations (#99)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mcquenji <60017181+mcquenji@users.noreply.github.com>
1 parent 024f75e commit 7f3f203

38 files changed

+312
-143
lines changed

lbplanner/classes/enums/CAPABILITY_FLAG_ORNONE.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class CAPABILITY_FLAG_ORNONE extends CAPABILITY_FLAG {
4747
* @link CAPABILITY
4848
*/
4949
public static function to_capability(int $num): string {
50-
if ($num === 0) { // TODO: put in translation strings.
51-
throw new \coding_exception('0 means the absence of capabilities, and thus cannot be converted to a capability');
50+
if ($num === 0) {
51+
throw new \coding_exception(get_string('err_enum_capability_none', 'local_lbplanner'));
5252
}
5353
return parent::to_capability($num);
5454
}

lbplanner/classes/helpers/config_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public static function add_customfield(): void {
5353

5454
$fieldcontroller = field_controller::create(0, $record, $categorycontroller);
5555
// Added the default attributes for the custom field.
56-
$fieldcontroller->set('name', 'LB Planer Task Type');
57-
$fieldcontroller->set('description', 'Tracks whether the task is GK/EK/TEST/M');
56+
$fieldcontroller->set('name', get_string('cf_name', 'local_lbplanner'));
57+
$fieldcontroller->set('description', get_string('cf_description', 'local_lbplanner'));
5858
$fieldcontroller->set('type', 'select');
5959
// Because moodle wants me to save the configdata as a json string, I have to do this.
6060
// I don't know why moodle does this, but it does. I don't like it. but I have to do it. so I do it.

lbplanner/classes/helpers/invite_helper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public static function structure(): external_single_structure {
5454
public static function assert_invite_pending(int $status) {
5555
if ($status !== PLAN_INVITE_STATE::PENDING) {
5656
$name = PLAN_INVITE_STATE::name_from($status);
57-
throw new \moodle_exception("Invite already {$name}");
57+
$translatedname = get_string('invite_state_' . strtolower($name), 'local_lbplanner');
58+
throw new \moodle_exception(get_string('err_invite_alr', 'local_lbplanner', $translatedname));
5859
}
5960
}
6061
}

lbplanner/classes/helpers/modules_helper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,17 @@ public static function determine_uinified_grade(int $grade, int $maxgrade, int $
125125
* @throws \moodle_exception
126126
*/
127127
public static function determine_type(int $cmid): int {
128+
// TODO: cache category controller.
128129
$catid = config_helper::get_category_id();
129130
if ($catid === -1) {
130-
throw new \moodle_exception('couldn\'t find custom fields category ID');
131+
throw new \moodle_exception(get_string('err_cf_nocatid', 'local_lbplanner'));
131132
}
132133
$categorycontroller = category_controller::create($catid);
133134
$instancedata = $categorycontroller->get_handler()->get_instance_data($cmid);
134135
if (count($instancedata) === 0) {
135-
throw new \moodle_exception("couldn't find any instance data for module ID {$cmid} in category ID {$catid}");
136+
throw new \moodle_exception(get_string('err_cf_nodata', 'local_lbplanner', ['cmid' => $cmid, 'catid' => $catid]));
136137
} else if (count($instancedata) > 1) {
137-
throw new \moodle_exception("found multiple data for module ID {$cmid} in category ID {$catid}");
138+
throw new \moodle_exception(get_string('err_cf_multidata', 'local_lbplanner', ['cmid' => $cmid, 'catid' => $catid]));
138139
}
139140
$type = intval($instancedata[array_key_last($instancedata)]->get_value()) - 1;
140141
if ($type === -1) {

lbplanner/classes/helpers/plan_helper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,19 @@ public static function copy_plan(int $planid, string $username): int {
261261
public static function remove_user(int $planid, int $userid, int $removeuserid): int {
262262
global $DB; // TODO: use global user object.
263263
if (self::get_owner($planid) != $userid) {
264-
throw new \moodle_exception('Access denied');
264+
throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner'));
265265
}
266266

267267
if (self::get_plan_id($removeuserid) != $planid) {
268-
throw new \moodle_exception('Cannot remove user from other plan');
268+
throw new \moodle_exception(get_string('err_plan_cantremove_userfromother', 'local_lbplanner'));
269269
}
270270

271271
if ($userid == $removeuserid) {
272-
throw new \moodle_exception('Cannot remove yourself');
272+
throw new \moodle_exception(get_string('err_plan_cantremove_yourself', 'local_lbplanner'));
273273
}
274274

275275
if (self::get_access_type($removeuserid, $planid) === PLAN_ACCESS_TYPE::OWNER) {
276-
throw new \moodle_exception('Cannot remove owner');
276+
throw new \moodle_exception(get_string('err_plan_cantremove_owner', 'local_lbplanner'));
277277
}
278278

279279
$newplanid = self::copy_plan($planid, user_helper::get_mdluser($removeuserid)->username);

lbplanner/classes/helpers/sentry_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static function init(): void {
8989
public static function transaction_start(string $name, string $op, ?array $data = null): ?Transaction {
9090
if (self::enabled()) {
9191
if (SentrySdk::getCurrentHub()->getSpan() !== null) {
92-
throw new \coding_exception('tried to start a new sentry transaction when there\'s already a span set');
92+
throw new \coding_exception(get_string('err_sentry_transactcoll', 'local_lbplanner'));
9393
}
9494
$ctx = TransactionContext::make()
9595
->setName($name)

lbplanner/classes/helpers/slot_helper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static function get_reservation(int $reservationid): reservation {
219219
$reservation = $DB->get_record(self::TABLE_RESERVATIONS, ['id' => $reservationid]);
220220

221221
if ($reservation === false) {
222-
throw new \moodle_exception('requested reservation does not exist');
222+
throw new \moodle_exception(get_string('err_slot_reservnoexist', 'local_lbplanner', $reservationid));
223223
}
224224

225225
return reservation::from_obj($reservation);
@@ -395,7 +395,7 @@ public static function calculate_slot_datetime(slot $slot, DateTimeImmutable $no
395395
// Move to next day this weekday occurs (doesn't move if it's the same as today).
396396
$slotdatetime = $now->modify('this ' . WEEKDAY::name_from($slot->weekday) . " {$slotdaytime}");
397397
if ($slotdatetime === false) {
398-
throw new \coding_exception('error while calculating slot datetime');
398+
throw new \coding_exception(get_string('err_slot_calcdatetime', 'local_lbplanner'));
399399
}
400400

401401
// Check if slot is before now (because time of day and such) and move it a week into the future if so.
@@ -449,7 +449,7 @@ public static function check_slot_supervisor(int $supervisorid, int $slotid): bo
449449
*/
450450
public static function assert_slot_supervisor(int $supervisorid, int $slotid): void {
451451
if (!self::check_slot_supervisor($supervisorid, $slotid)) {
452-
throw new \moodle_exception('Insufficient Permission: you\'re not supervisor of this slot');
452+
throw new \moodle_exception(get_string('err_slot_urnotsupervisor', 'local_lbplanner'));
453453
}
454454
}
455455
}

lbplanner/classes/helpers/user_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function get_user(int $userid): user {
7979

8080
// Create empty plan for newly registered user.
8181
$plan = new \stdClass();
82-
$plan->name = 'Plan for ' . ($eduplanneruser->get_mdluser()->username);
82+
$plan->name = get_string('plan_defaultname', 'local_lbplanner', $eduplanneruser->get_mdluser()->username);
8383
$planid = $DB->insert_record(plan_helper::TABLE, $plan);
8484
$eduplanneruser->set_planid($planid);
8585

lbplanner/classes/model/course.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class course {
7171
* @param bool $enabled whether the course is enabled
7272
*/
7373
public function __construct(int $id, int $courseid, int $userid, string $shortname, string $color, bool $enabled) {
74+
// TODO: private constructor, remove checks, separate public function with checks.
7475
$this->id = $id;
7576
$this->courseid = $courseid;
7677
$this->userid = $userid;
@@ -110,7 +111,7 @@ public function set_fresh(int $id) {
110111
*/
111112
public function set_color(string $color) {
112113
if ($color[0] !== '#') {
113-
throw new \coding_exception("incorrect color format - must be either #RGB or #RRGGBB, got \"{$color}\" instead");
114+
throw new \coding_exception(get_string('err_color_wrongformat', 'local_lbplanner', $color));
114115
}
115116
$len = strlen($color);
116117
if ($len === 4) {
@@ -122,11 +123,11 @@ public function set_color(string $color) {
122123
// Format #RRGGBB.
123124
$rrggbb = $color;
124125
} else {
125-
throw new \coding_exception("incorrect color format - got incorrect length of {$len}");
126+
throw new \coding_exception(get_string('err_color_wronglength', 'local_lbplanner', $len));
126127
}
127128
$rrggbb = strtoupper($rrggbb);
128129
if (preg_match('/^#[1-9A-F]{6}$/', $rrggbb) === false) {
129-
throw new \coding_exception("incorrect color format - found non-hexadecimal character in color \"{$color}\"");
130+
throw new \coding_exception(get_string('err_color_nonhexadecimal', 'local_lbplanner', $color));
130131
}
131132
$this->color = $rrggbb;
132133
}
@@ -139,7 +140,7 @@ public function set_color(string $color) {
139140
public function set_shortname(string $shortname) {
140141
$length = strlen($shortname);
141142
if ($length > 5 || $length < 0) {
142-
throw new \moodle_exception("shortname length must be <=5 and >0, but is {$length} instead");
143+
throw new \moodle_exception(get_string('err_course_shortnamelength', 'local_lbplanner', $length));
143144
}
144145
$this->shortname = $shortname;
145146
}
@@ -173,7 +174,7 @@ public static function prepare_shortname(string $shortname): string {
173174
*/
174175
public function set_mdlcourse(\stdClass $mdlcourse): void {
175176
if ($this->mdlcourse !== null) {
176-
throw new \coding_exception('tried to set cached mdluser twice');
177+
throw new \coding_exception(get_string('err_doublechacheset', 'local_lbplanner', 'mdlcourse'));
177178
}
178179
$this->mdlcourse = $mdlcourse;
179180
}

lbplanner/classes/model/module.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function get_assignid(): int {
139139
if ($this->cmid !== null) {
140140
$this->assignid = $this->get_cmobj()->instance;
141141
} else {
142-
throw new \coding_exception('requested assignid, but no cmid');
142+
throw new \coding_exception(get_string('err_mod_assnocmid', 'local_lbplanner'));
143143
}
144144
}
145145
return $this->assignid;
@@ -185,11 +185,11 @@ public function get_cmobj(): \stdClass {
185185
['id' => $this->cmid, 'module' => modules_helper::get_assign_module_id()]
186186
);
187187
if ($res === false) {
188-
throw new \moodle_exception("couldn't get course module with cmid {$this->cmid}");
188+
throw new \moodle_exception(get_string('err_mod_cmidnocm', 'local_lbplanner', $this->cmid));
189189
}
190190
} else {
191191
if ($this->assignid === null) {
192-
throw new \coding_exception('tried to query cmid on a module object without assignid');
192+
throw new \coding_exception(get_string('err_mod_cmidnoass', 'local_lbplanner'));
193193
}
194194
$courseid = $this->get_courseid();
195195
$res = $DB->get_record(
@@ -201,9 +201,11 @@ public function get_cmobj(): \stdClass {
201201
]
202202
);
203203
if ($res === false) {
204-
throw new \moodle_exception(
205-
"couldn't get course module with assignid {$this->assignid} and courseid {$courseid}"
206-
);
204+
throw new \moodle_exception(get_string(
205+
'err_mod_assnocm',
206+
'local_lbplanner',
207+
['assignid' => $this->assignid, 'courseid' => $courseid],
208+
));
207209
}
208210
}
209211
$this->cmobj = $res;
@@ -243,7 +245,7 @@ public function get_courseid(): int {
243245
if ($this->cmid !== null) {
244246
$viacm = true;
245247
} else if ($this->cmid === null) {
246-
throw new \coding_exception('invalid module model: neither cmid nor assignid defined');
248+
throw new \coding_exception(get_string('err_mod_nocmidnorass', 'local_lbplanner'));
247249
}
248250
}
249251
}

0 commit comments

Comments
 (0)