Reputation: 68
Translate on Moodle using "get_string" for a specific language.I am trying to get a translation of my plugin block on Moodle in a specific language. but I cannot. here is a code example:
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",
"<h1>" . get_string('lessontitle', 'block_smartteacher', null, $course_module->lang) . ": {$lessonPage->title}</h1>" .
"<h2>" . get_string('lessondescription', 'block_smartteacher', null, $course_module->lang) . ": {$lesson->intro}</h2>" .
"<h3>" . get_string('lessoncontent', 'block_smartteacher', null, $course_module->lang) . ": {$lessonPage->contents}</h3>",
$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();
}
}
Is my way wrong get_string('lessontitle', 'block_smartteacher', null, $course_module->lang)
?
I got that lang is correct its return "ar"
Upvotes: 0
Views: 23