Merge branch 'MDL-80185-401' of https://github.com/paulholden/moodle into MOODLE_401_STABLE

This commit is contained in:
Sara Arjona
2023-12-04 11:00:56 +01:00
3 changed files with 16 additions and 7 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ class language_menu implements \renderable, \templatable {
if ($langparam) {
$attributes = [
'data-lang' => $langparam,
'lang' => $langparam,
'lang' => get_html_lang_attribute_value($langparam),
];
}
$lang = new \action_menu_link_secondary($node['url'], null, $node['title'], $attributes);
+3 -2
View File
@@ -1163,9 +1163,10 @@ EXPECTED;
*/
public function get_html_lang_attribute_value_provider() {
return [
'Empty lang code' => [' ', 'unknown'],
'Empty lang code' => [' ', 'en'],
'English' => ['en', 'en'],
'English, US' => ['en_us', 'en-us'],
'English, US' => ['en_us', 'en'],
'Unknown' => ['xx', 'en'],
];
}
+12 -4
View File
@@ -2283,11 +2283,19 @@ function highlightfast($needle, $haystack) {
* @return string
*/
function get_html_lang_attribute_value(string $langcode): string {
if (empty(trim($langcode))) {
// If the language code passed is an empty string, return 'unknown'.
return 'unknown';
$langcode = clean_param($langcode, PARAM_LANG);
if ($langcode === '') {
return 'en';
}
return str_replace('_', '-', $langcode);
// Grab language ISO code from lang config. If it differs from English, then it's been specified and we can return it.
$langiso = (string) (new lang_string('iso6391', 'core_langconfig', null, $langcode));
if ($langiso !== 'en') {
return $langiso;
}
// Where we cannot determine the value from lang config, use the first two characters from the lang code.
return substr($langcode, 0, 2);
}
/**