Skip to content

Commit

Permalink
MDL-69788 lang: fallback to all translations if misconfigured.
Browse files Browse the repository at this point in the history
If given translation list contains only invalid entries, fallback
to returning the complete list of available language translations.
  • Loading branch information
paulholden committed Oct 16, 2020
1 parent 149fdcf commit 59ec5b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/classes/string_manager_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,13 @@ public function get_list_of_translations($returnall = false) {
$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.
Expand Down Expand Up @@ -584,7 +590,12 @@ public function get_list_of_translations($returnall = false) {
}
}

return $languages;
// If there are no valid enabled translations, then return all languages.
if (!empty($languages)) {
return $languages;
} else {
return $cachedlist;
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/tests/string_manager_standard_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ public function test_get_list_of_translations() {

$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);
}
Expand Down

0 comments on commit 59ec5b1

Please sign in to comment.