Skip to content

Commit a61ab50

Browse files
committed
Correctly load UTF-8 system locales
1 parent c2650ba commit a61ab50

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

SETUP/ci/check_security.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// others are added from the current set until they get updated.
1414
$ok_system_calls = [
1515
"pinc/forum_interface_phpbb3.inc",
16-
"pinc/languages.inc",
1716
"pinc/phpbb3.inc",
1817
"pinc/POFile.inc",
1918
"pinc/Project.inc",

pinc/languages.inc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
include_once($relPath.'lang_data.inc');
88
include_once($relPath.'iso_lang_list.inc');
99

10+
use Symfony\Component\Process\Process;
11+
1012
function lang_code($language_code)
1113
{
1214
global $locales;
@@ -120,14 +122,20 @@ function lang_direction($langcode = false)
120122
*/
121123
function get_installed_system_locales()
122124
{
123-
static $system_locales = [];
124-
if ($system_locales) {
125-
return $system_locales;
125+
static $utf8_locales = [];
126+
if ($utf8_locales) {
127+
return $utf8_locales;
128+
}
129+
130+
$process = new Process(["locale", "-a"]);
131+
$process->run();
132+
if (!$process->isSuccessful()) {
133+
throw new RuntimeException("Failed loading system locales.");
126134
}
127135

128-
exec("locale -a", $system_locales);
136+
$system_locales = explode("\n", $process->getOutput());
129137

130-
// exclude all non-UTF-8 locales
138+
// only include UTF-8 locales, but strip the .utf8 off the end
131139
$utf8_locales = [];
132140
foreach ($system_locales as $locale) {
133141
if (endswith($locale, '.utf8')) {

0 commit comments

Comments
 (0)