From a7f720d82545bacf062339eeb930581f678a6ad6 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 9 Dec 2023 11:39:53 +0100 Subject: [PATCH] ensure English is always added to available languages, fixes #1208 bug got introduced in 3668f1e3f4808d7232606349035c6a43c5a84c23 and started affecting release after 896a49c8cf96ae9351796bd84050d2a0b249ddb3 --- CHANGELOG.md | 3 +++ lib/Data/Filesystem.php | 3 ++- lib/I18n.php | 15 +++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 754af8b5..4f6cc164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # PrivateBin version history +## 1.6.2 (not yet released) +* FIXED: English not selectable when languageselection enabled (#1208) + ## 1.6.1 (2023-12-04) * ADDED: Right-To-Left (RTL) support for Arabic & Hebrew (#1174) * CHANGED: Upgrading libraries to: DOMpurify 3.0.6 diff --git a/lib/Data/Filesystem.php b/lib/Data/Filesystem.php index 38cd70ac..2ac594a4 100644 --- a/lib/Data/Filesystem.php +++ b/lib/Data/Filesystem.php @@ -13,6 +13,7 @@ namespace PrivateBin\Data; use Exception; +use GlobIterator; use PrivateBin\Json; /** @@ -394,7 +395,7 @@ class Filesystem extends AbstractData public function getAllPastes() { $pastes = array(); - foreach (new \GlobIterator($this->_path . self::PASTE_FILE_PATTERN) as $file) { + foreach (new GlobIterator($this->_path . self::PASTE_FILE_PATTERN) as $file) { if ($file->isFile()) { $pastes[] = $file->getBasename('.php'); } diff --git a/lib/I18n.php b/lib/I18n.php index 31eedb47..2d7d73b0 100644 --- a/lib/I18n.php +++ b/lib/I18n.php @@ -12,6 +12,9 @@ namespace PrivateBin; +use AppendIterator; +use GlobIterator; + /** * I18n * @@ -193,10 +196,14 @@ class I18n public static function getAvailableLanguages() { if (count(self::$_availableLanguages) == 0) { - $i18n = dir(self::_getPath()); - while (false !== ($file = $i18n->read())) { - if (preg_match('/^([a-z]{2,3}).json$/', $file, $match) === 1) { - self::$_availableLanguages[] = $match[1]; + self::$_availableLanguages[] = 'en'; // en.json is not part of the release archive + $languageIterator = new AppendIterator(); + $languageIterator->append(new GlobIterator(self::_getPath('??.json'))); + $languageIterator->append(new GlobIterator(self::_getPath('???.json'))); // for jbo + foreach ($languageIterator as $file) { + $language = $file->getBasename('.json'); + if ($language != 'en') { + self::$_availableLanguages[] = $language; } } }