From d4ba0359cf115b8c83ea93c18293cb1d509da1b9 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Fri, 27 May 2022 15:49:54 +0800 Subject: [PATCH] MDL-72885 core: Use get_html_lang_attribute_value() Use get_html_lang_attribute_value() for formatting language codes for the HTML lang attribute. --- h5p/classes/editor_framework.php | 2 +- h5p/classes/framework.php | 2 +- lib/classes/content/export/zipwriter.php | 2 +- lib/weblib.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/h5p/classes/editor_framework.php b/h5p/classes/editor_framework.php index dc4e4216990..0ab8b956338 100644 --- a/h5p/classes/editor_framework.php +++ b/h5p/classes/editor_framework.php @@ -84,7 +84,7 @@ class editor_framework implements H5peditorStorage { // If current language has a dependency, then request it. if (count($dependencies) > 1) { - $parentlanguage = str_replace('_', '-', $dependencies[count($dependencies) - 2]); + $parentlanguage = get_html_lang_attribute_value($dependencies[count($dependencies) - 2]); $result = $this->get_language_record($name, $major, $minor, $parentlanguage); } } diff --git a/h5p/classes/framework.php b/h5p/classes/framework.php index 4c1241b83d1..c43fe95f1f6 100644 --- a/h5p/classes/framework.php +++ b/h5p/classes/framework.php @@ -1610,7 +1610,7 @@ class framework implements H5PFrameworkInterface { } // Get current language in Moodle. - $language = str_replace('_', '-', strtolower(\current_language())); + $language = get_html_lang_attribute_value(strtolower(\current_language())); // Try to map. return $map[$language] ?? $language; diff --git a/lib/classes/content/export/zipwriter.php b/lib/classes/content/export/zipwriter.php index 438b2e32aa8..5666cf3c83d 100644 --- a/lib/classes/content/export/zipwriter.php +++ b/lib/classes/content/export/zipwriter.php @@ -255,7 +255,7 @@ class zipwriter { $templatedata->global = (object) [ 'righttoleft' => right_to_left(), - 'language' => str_replace('_', '-', current_language()), + 'language' => get_html_lang_attribute_value(current_language()), 'sitename' => format_string($SITE->fullname, true, ['context' => context_system::instance()]), 'siteurl' => $CFG->wwwroot, 'pathtotop' => $this->get_relative_context_path($context, $this->rootcontext, '/'), diff --git a/lib/weblib.php b/lib/weblib.php index ed2b73f163f..ea7a294bf27 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2242,7 +2242,7 @@ function get_html_lang($dir = false) { } } // Accessibility: added the 'lang' attribute to $direction, used in theme tag. - $language = str_replace('_', '-', current_language()); + $language = get_html_lang_attribute_value(current_language()); @header('Content-Language: '.$language); return ($direction.' lang="'.$language.'" xml:lang="'.$language.'"'); }