Holen Sie sich die Übersetzung auf Moodle mit „get_string“ für eine bestimmte Sprache
Posted: 12 Jan 2025, 09:06
Übersetzen Sie auf Moodle mit „get_string“ für eine bestimmte Sprache. Ich versuche, eine Übersetzung meines Plugin-Blocks auf Moodle in einer bestimmten Sprache zu erhalten. aber ich kann nicht. Hier ist ein Codebeispiel:
Liegt mein Weg falsch get_string('lessontitle', 'block_smartteacher', null, $course_module->lang) ?
Ich habe verstanden, dass die Rückgabe von lang korrekt ist "ar"
Code: Select all
public static function course_lesson_created(\mod_lesson\event\page_created $event)
{
global $DB;
$event_data = $event->get_data();
// Get the course ID from the event data
if (isset($event_data['target']) && $event_data['target'] == "page") {// if lesson page
$objectid = $event_data['objectid'];
// Query the database to get the lesson page
$lessonPage = $DB->get_record('lesson_pages', ['id' => $objectid], '*', MUST_EXIST);
$lesson = $DB->get_record('lesson', ['id' => $lessonPage->lessonid], '*', MUST_EXIST);
$course_module = $DB->get_record('course_modules', ['id' => $event_data['contextinstanceid']], '*', MUST_EXIST);
$response = self::create_MoodleContentDetail(
$lessonPage->title,
$lesson->intro,
$event_data["action"],
"lesson",
"" . get_string('lessontitle', 'block_smartteacher', null, $course_module->lang) . ": {$lessonPage->title}" .
"" . get_string('lessondescription', 'block_smartteacher', null, $course_module->lang) . ": {$lesson->intro}" .
"" . get_string('lessoncontent', 'block_smartteacher', null, $course_module->lang) . ": {$lessonPage->contents}",
$course_module->lang,
$course_module->course, // courseId
$course_module->module, // moduleTypeId
$course_module->id, // moduleId
$course_module->section // sectionId
);
// var_dump(json_encode($event_data));
// var_dump(json_encode($response));
/* var_dump(get_string('lessoncontent', 'block_smartteacher', null, $course_module->lang));
var_dump(get_string('lessoncontent', 'block_smartteacher', null, "ar"));
var_dump(get_string('lessoncontent', 'block_smartteacher', null, "en")); */
// var_dump($course_module->lang == "ar");
// var_dump($course_module->lang == "en");
// var_dump($course_module->lang == "ar" ? "ar" : "en");
// die();
}
}
Ich habe verstanden, dass die Rückgabe von lang korrekt ist "ar"