mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
Merge branch 'MDL-69788' of https://github.com/paulholden/moodle
This commit is contained in:
commit
a9ab6a1db7
5 changed files with 85 additions and 2 deletions
|
@ -4933,6 +4933,36 @@ class admin_setting_langlist extends admin_setting_configtext {
|
|||
parent::__construct('langlist', get_string('langlist', 'admin'), get_string('configlanglist', 'admin'), '', PARAM_NOTAGS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that each language identifier exists on the site
|
||||
*
|
||||
* @param string $data
|
||||
* @return bool|string True if validation successful, otherwise error string
|
||||
*/
|
||||
public function validate($data) {
|
||||
$parentcheck = parent::validate($data);
|
||||
if ($parentcheck !== true) {
|
||||
return $parentcheck;
|
||||
}
|
||||
|
||||
if ($data === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Normalize language identifiers.
|
||||
$langcodes = array_map('trim', explode(',', $data));
|
||||
foreach ($langcodes as $langcode) {
|
||||
// If the langcode contains optional alias, split it out.
|
||||
[$langcode, ] = preg_split('/\s*\|\s*/', $langcode, 2);
|
||||
|
||||
if (!get_string_manager()->translation_exists($langcode)) {
|
||||
return get_string('invalidlanguagecode', 'error', $langcode);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the new setting
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue