mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
Merge branch 'MDL-80185' of https://github.com/paulholden/moodle
This commit is contained in:
commit
33ffa3b6a2
@ -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);
|
||||
|
@ -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'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -2297,11 +2297,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user