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 authored and brendanheywood committed Sep 11, 2024
1 parent a08c54d commit 7eb18e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@
$data['lockreason'] = format_text($data['lockreason']);
$tabs = new tabs($url);

$data['lang'] = get_config('core', 'lang');
// 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');

$data['course'] = helper::course_display_link($data['courseid']);

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

0 comments on commit 7eb18e4

Please sign in to comment.