mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +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
|
||||
*
|
||||
|
|
|
@ -533,7 +533,13 @@ class core_string_manager_standard implements core_string_manager {
|
|||
$languages[$langcode] = !empty($this->transaliases[$langcode]) ? $this->transaliases[$langcode] : $langname;
|
||||
}
|
||||
}
|
||||
return $languages;
|
||||
|
||||
// If there are no valid enabled translations, then return all languages.
|
||||
if (!empty($languages)) {
|
||||
return $languages;
|
||||
} else {
|
||||
return $cachedlist;
|
||||
}
|
||||
}
|
||||
|
||||
// Get all languages available in system.
|
||||
|
@ -584,7 +590,12 @@ class core_string_manager_standard implements core_string_manager {
|
|||
}
|
||||
}
|
||||
|
||||
return $languages;
|
||||
// If there are no valid enabled translations, then return all languages.
|
||||
if (!empty($languages)) {
|
||||
return $languages;
|
||||
} else {
|
||||
return $cachedlist;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -140,6 +140,13 @@ class core_string_manager_standard_testcase extends advanced_testcase {
|
|||
|
||||
$this->assertEquals(['en' => 'En'], $stringman->get_list_of_translations());
|
||||
|
||||
// Set invalid config, ensure original list is returned.
|
||||
set_config('langlist', 'xx');
|
||||
$this->assertEquals(['en' => 'English (en)'], get_string_manager(true)->get_list_of_translations());
|
||||
|
||||
set_config('langlist', 'xx,en|En');
|
||||
$this->assertEquals(['en' => 'En'], get_string_manager(true)->get_list_of_translations());
|
||||
|
||||
set_config('langlist', '');
|
||||
get_string_manager(true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue