mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
Merge branch 'MDL-65236-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
1ba1bb79e8
@ -265,7 +265,7 @@ $string['configiplookup'] = 'When you click on an IP address (such as 34.12.222.
|
||||
$string['configkeeptagnamecase'] = 'Check this if you want tag names to keep the original casing as entered by users who created them';
|
||||
$string['configlang'] = 'Choose a default language for the whole site. Users can override this setting using the language menu or the setting in their personal profile.';
|
||||
$string['configlangstringcache'] = 'Caches all the language strings into compiled files in the data directory. If you are translating Moodle or changing strings in the Moodle source code then you may want to switch this off. Otherwise leave it on to see performance benefits.';
|
||||
$string['configlanglist'] = 'Leave this blank to allow users to choose from any language you have in this installation of Moodle. However, you can shorten the language menu by entering a comma-separated list of language codes that you want. For example: en,es_es,fr,it';
|
||||
$string['configlanglist'] = 'If left blank, all languages installed on the site will be displayed in the language menu. Alternatively, the language menu may be shortened by entering a list of language codes separated by commas e.g. en,de,fr. If desired, a different name for the language than the language pack name may be specified using the format: language code|language name e.g. en_kids|English,de_kids|Deutsch.';
|
||||
$string['configlangmenu'] = 'Choose whether or not you want to display the general-purpose language menu on the home page, login page etc. This does not affect the user\'s ability to set the preferred language in their own profile.';
|
||||
$string['configlatinexcelexport'] = 'Choose the encoding for Excel exports.';
|
||||
$string['configlocale'] = 'Choose a sitewide locale - this will override the format and language of dates for all language packs (though names of days in calendar are not affected). You need to have this locale data installed on your operating system (eg for linux en_US.UTF-8 or es_ES.UTF-8). In most cases this field should be left blank.';
|
||||
|
@ -45,6 +45,8 @@ class core_string_manager_standard implements core_string_manager {
|
||||
protected $countgetstring = 0;
|
||||
/** @var bool use disk cache */
|
||||
protected $translist;
|
||||
/** @var array language aliases to use in the language selector */
|
||||
protected $transaliases = [];
|
||||
/** @var cache stores list of available translations */
|
||||
protected $menucache;
|
||||
/** @var array list of cached deprecated strings */
|
||||
@ -56,12 +58,14 @@ class core_string_manager_standard implements core_string_manager {
|
||||
* @param string $otherroot location of downloaded lang packs - usually $CFG->dataroot/lang
|
||||
* @param string $localroot usually the same as $otherroot
|
||||
* @param array $translist limit list of visible translations
|
||||
* @param array $transaliases aliases to use for the languages in the language selector
|
||||
*/
|
||||
public function __construct($otherroot, $localroot, $translist) {
|
||||
public function __construct($otherroot, $localroot, $translist, $transaliases = []) {
|
||||
$this->otherroot = $otherroot;
|
||||
$this->localroot = $localroot;
|
||||
if ($translist) {
|
||||
$this->translist = array_combine($translist, $translist);
|
||||
$this->transaliases = $transaliases;
|
||||
} else {
|
||||
$this->translist = array();
|
||||
}
|
||||
@ -521,8 +525,8 @@ class core_string_manager_standard implements core_string_manager {
|
||||
}
|
||||
// Return only enabled translations.
|
||||
foreach ($cachedlist as $langcode => $langname) {
|
||||
if (isset($this->translist[$langcode])) {
|
||||
$languages[$langcode] = $langname;
|
||||
if (array_key_exists($langcode, $this->translist)) {
|
||||
$languages[$langcode] = !empty($this->transaliases[$langcode]) ? $this->transaliases[$langcode] : $langname;
|
||||
}
|
||||
}
|
||||
return $languages;
|
||||
@ -572,7 +576,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||
$languages = array();
|
||||
foreach ($cachedlist as $langcode => $langname) {
|
||||
if (isset($this->translist[$langcode])) {
|
||||
$languages[$langcode] = $langname;
|
||||
$languages[$langcode] = !empty($this->transaliases[$langcode]) ? $this->transaliases[$langcode] : $langname;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7083,11 +7083,20 @@ function get_string_manager($forcereload=false) {
|
||||
if ($singleton === null) {
|
||||
if (empty($CFG->early_install_lang)) {
|
||||
|
||||
$transaliases = array();
|
||||
if (empty($CFG->langlist)) {
|
||||
$translist = array();
|
||||
} else {
|
||||
$translist = explode(',', $CFG->langlist);
|
||||
$translist = array_map('trim', $translist);
|
||||
// Each language in the $CFG->langlist can has an "alias" that would substitute the default language name.
|
||||
foreach ($translist as $i => $value) {
|
||||
$parts = preg_split('/\s*\|\s*/', $value, 2);
|
||||
if (count($parts) == 2) {
|
||||
$transaliases[$parts[0]] = $parts[1];
|
||||
$translist[$i] = $parts[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($CFG->config_php_settings['customstringmanager'])) {
|
||||
@ -7097,7 +7106,7 @@ function get_string_manager($forcereload=false) {
|
||||
$implements = class_implements($classname);
|
||||
|
||||
if (isset($implements['core_string_manager'])) {
|
||||
$singleton = new $classname($CFG->langotherroot, $CFG->langlocalroot, $translist);
|
||||
$singleton = new $classname($CFG->langotherroot, $CFG->langlocalroot, $translist, $transaliases);
|
||||
return $singleton;
|
||||
|
||||
} else {
|
||||
@ -7110,7 +7119,7 @@ function get_string_manager($forcereload=false) {
|
||||
}
|
||||
}
|
||||
|
||||
$singleton = new core_string_manager_standard($CFG->langotherroot, $CFG->langlocalroot, $translist);
|
||||
$singleton = new core_string_manager_standard($CFG->langotherroot, $CFG->langlocalroot, $translist, $transaliases);
|
||||
|
||||
} else {
|
||||
$singleton = new core_string_manager_install();
|
||||
|
@ -124,6 +124,25 @@ class core_string_manager_standard_testcase extends advanced_testcase {
|
||||
$this->assertTrue($stringman->string_exists($matches[1], $matches[2]),
|
||||
"String {$string} appearing in one of the lang/en/deprecated.txt files does not exist");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for $CFG->langlist (without installation of additional languages)
|
||||
*/
|
||||
public function test_get_list_of_translations() {
|
||||
$this->resetAfterTest();
|
||||
$stringman = get_string_manager();
|
||||
|
||||
$this->assertEquals(['en' => 'English (en)'], $stringman->get_list_of_translations());
|
||||
|
||||
set_config('langlist', 'en|En');
|
||||
get_string_manager(true);
|
||||
$stringman = get_string_manager();
|
||||
|
||||
$this->assertEquals(['en' => 'En'], $stringman->get_list_of_translations());
|
||||
|
||||
set_config('langlist', '');
|
||||
get_string_manager(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user