Skip to content

Commit

Permalink
Issue #345: Use locale, not langpack name, for JS locale
Browse files Browse the repository at this point in the history
Moodle langpack names are not required to be valid JavaScript locale
names. Basic ones like "en" are, but custom ones like "en_custom"
are not.
  • Loading branch information
agwells committed Jun 5, 2024
1 parent 0a02afa commit 7d3a852
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 55 deletions.
30 changes: 7 additions & 23 deletions profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@

$profile = new profile($profileid);

$prevurl = new moodle_url('/admin/tool/excimer/' . $report. '.php', ['group' => $profile->get('scriptgroup')]);
$PAGE->navbar->add($profile->get('scriptgroup'), $prevurl);
$prevurl = new moodle_url('/admin/tool/excimer/' . $report. '.php', ['group' => $profile->get('groupby')]);
$PAGE->navbar->add($profile->get('groupby'), $prevurl);

$PAGE->navbar->add($profile->get('request') . $profile->get('pathinfo'));
$PAGE->set_title($pluginname);
Expand Down Expand Up @@ -121,23 +121,7 @@
$data['created'] = userdate($data['created']);
$data['finished'] = userdate($data['finished']);

$duration = $data['duration'];
$data['duration'] = helper::duration_display($duration, true);
if (isset($data['lockwait'])) {
$lockwait = $data['lockwait'];
$data['lockwait'] = helper::duration_display($lockwait, true);
$data['lockheld'] = helper::duration_display($data['lockheld'], true);
$data['lockwaiturl'] = helper::lockwait_display_link($data['lockwaiturl'], $lockwait);
$data['lockwaiturlhelp'] = helper::lockwait_display_help($OUTPUT, $data['lockwaiturl']);

$processing = $duration - $lockwait;
if (($processing / $duration) < 0.1 && $processing < 10) {
\core\notification::warning(get_string('lockwaitnotification', 'tool_excimer'));
$data['waitnotification'] = true;
}
} else {
$data['lockwaiturl'] = '-';
}
$data['duration'] = format_time(round($data['duration'], 3));

$data['request'] = helper::full_request($profile->to_record());

Expand Down Expand Up @@ -196,12 +180,12 @@
$data['lockreason'] = format_text($data['lockreason']);
$tabs = new tabs($url);

$data['lang'] = get_config('core', 'lang');

$data['course'] = helper::course_display_link($data['courseid']);
$data['tabs'] = $tabs->export_for_template($output)['tabs'];
// JavaScript locale string. Arguably "localecldr/langconfig" would be a better
// choice, but it's not present in Totara langpacks.
$data['locale'] = get_string('iso6391', 'langconfig');

echo $output->header();
echo $output->render_tabs($tabs);
echo $output->render_from_template('tool_excimer/profile', $data);
echo $output->render_from_template('tool_excimer/flamegraph', $data);
echo $output->render_from_template('tool_excimer/memoryusagegraph', $data);
Expand Down
6 changes: 3 additions & 3 deletions templates/flamegraph.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
Context variables required for this template:
* id - The id of the profile
* lang - Language setting
* locale - Language setting (a BCP 47 language tag)
Example context (json):
{
"id" : 3,
"lang" : "en"
"locale" : "en"
}
}}

Expand Down Expand Up @@ -73,7 +73,7 @@ function displaysamplestats(d) {
}
const percentage = ((d.x1 - d.x0) * 100).toFixed(3);
const samplecount = d.value.toLocaleString("{{lang}}");
const samplecount = d.value.toLocaleString("{{locale}}");
return d.data.name + ` (${percentage}%, ${samplecount} {{#str}} samples, tool_excimer {{/str}}, {{#str}} duration, tool_excimer {{/str}} ~ ${durationstr}})`;
}
Expand Down
6 changes: 4 additions & 2 deletions templates/memoryusagegraph.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
Context variables required for this template:
* id - The id of the profile
* locale - Language setting (a BCP 47 language tag)
Example context (json):
{
"id" : 3
"id" : 3,
"locale": "en"
}
}}

Expand Down Expand Up @@ -177,7 +179,7 @@ function processGraph(id, data) {
.attr("cx", function(d) { return x(d.sampleindex); })
.attr("cy", function(d) { return y(d.value); })
.on("mouseover", function(event, d) {
const sampleindex = d.sampleindex.toLocaleString('{{lang}}');
const sampleindex = d.sampleindex.toLocaleString('{{locale}}');
div.transition()
.duration(200)
.style("opacity", .9);
Expand Down
30 changes: 3 additions & 27 deletions templates/profile.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@
"buffering" : 1,
"fullname" : "Admin User",
"userlink" : "https://some.domain://user/profile?id=1",
"course": "<a> My course </a>"
"tabs" : "<ul></ul>"
}
}}
<h3 style="overflow-wrap: anywhere;">{{{responsecode}}} {{method}} {{{request}}}</h3>
{{> core/tabtree}}
<h3>{{{responsecode}}} {{method}} {{{request}}}</h3>
<p>{{{delete_button}}} {{{delete_all_button}}} {{{profile_lock_button}}}</p>
{{#lockreason}}
Expand Down Expand Up @@ -124,20 +125,6 @@
<th>{{#str}} field_memoryusagemax, tool_excimer {{/str}}</th>
<td>{{memoryusagemax}}</td>
</tr>
<tr>
<th{{#waitnotification}} class="alert alert-warning"{{/waitnotification}}>{{#str}} field_lockwait, tool_excimer {{/str}}</th>
<td{{#waitnotification}} class="alert alert-warning"{{/waitnotification}}>
{{#lockwait}}{{{lockwait}}}{{/lockwait}}
{{^lockwait}}{{#str}} unknown, tool_excimer {{/str}}{{/lockwait}}
</td>
</tr>
<tr>
<th>{{#str}} field_lockheld, tool_excimer {{/str}}</th>
<td>
{{#lockheld}}{{{lockheld}}}{{/lockheld}}
{{^lockheld}}{{#str}} unknown, tool_excimer {{/str}}{{/lockheld}}
</td>
</tr>
</table>
</div>
<div class="">
Expand Down Expand Up @@ -180,17 +167,6 @@
<th>{{#str}} field_dbreplicareads, tool_excimer {{/str}}</th>
<td>{{dbreplicareads}}</td>
</tr>
<tr>
<th>{{#str}} field_courseid, tool_excimer {{/str}}</th>
<td>{{{ course }}}</td>
</tr>
<tr>
<th>{{#str}} field_lockwaiturl, tool_excimer {{/str}}</th>
<td>
{{{lockwaiturl}}}
{{#lockwaiturlhelp}} {{>core/help_icon}} {{/lockwaiturlhelp}}
</td>
</tr>
</table>
</div>
</div>
Expand Down

0 comments on commit 7d3a852

Please sign in to comment.