From b08718fcc3b422b1146d07172864f1742b014f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20=C3=9Ar?= Date: Wed, 5 Jan 2022 00:33:04 +0100 Subject: [PATCH 1/5] Add native language names to language selector --- src/Core/L10n.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 90d4c0fe5..33c670443 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -340,9 +340,10 @@ class L10n * * Scans the view/lang directory for the existence of "strings.php" files, and * returns an alphabetical list of their folder names (@-char language codes). - * Adds the english language if it's missing from the list. + * Adds the english language if it's missing from the list. Folder names are + * replaced by nativ language names. * - * Ex: array('de' => 'de', 'en' => 'en', 'fr' => 'fr', ...) + * Ex: array('de' => 'Deutsch', 'en' => 'English', 'fr' => 'Français', ...) * * @return array */ @@ -350,6 +351,33 @@ class L10n { $langs = []; $strings_file_paths = glob('view/lang/*/strings.php'); + $lang_names = [ + 'ar' => 'العربية', + 'bg' => 'Български', + 'ca' => 'Català', + 'cs' => 'Česky', + 'de' => 'Deutsch', + 'en-gb' => 'English (United Kingdom)', + 'en-us' => 'English (United States)', + 'en' => 'English (Default)', + 'eo' => 'Esperanto', + 'es' => 'Español', + 'et' => 'Eesti', + 'fi-fi' => 'Suomi', + 'fr' => 'Français', + 'hu' => 'Magyar', + 'is' => 'Íslenska', + 'it' => 'Italiano', + 'ja' => '日本語', + 'nb-no' => 'Norsk bokmål', + 'nl' => 'Nederlands', + 'pl' => 'Polski', + 'pt-br' => 'Português Brasileiro', + 'ro' => 'Română', + 'ru' => 'Русский', + 'sv' => 'Svenska', + 'zh-cn' => '简体中文', + ]; if (is_array($strings_file_paths) && count($strings_file_paths)) { if (!in_array('view/lang/en/strings.php', $strings_file_paths)) { @@ -358,7 +386,7 @@ class L10n asort($strings_file_paths); foreach ($strings_file_paths as $strings_file_path) { $path_array = explode('/', $strings_file_path); - $langs[$path_array[2]] = $path_array[2]; + $langs[$path_array[2]] = isset($lang_names[$path_array[2]]) ? $lang_names[$path_array[2]] : $path_array[2]; } } return $langs; From b1237624595adc0d2c87cbbc0e80e8647c997104 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 23 Jan 2022 20:08:12 +0100 Subject: [PATCH 2/5] Move language names to constant --- src/Core/L10n.php | 57 ++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 33c670443..40aa24732 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -35,6 +35,34 @@ class L10n { /** @var string The default language */ const DEFAULT = 'en'; + /** @var string[] The language names in their language */ + const LANG_NAMES = [ + 'ar' => 'العربية', + 'bg' => 'Български', + 'ca' => 'Català', + 'cs' => 'Česky', + 'de' => 'Deutsch', + 'en-gb' => 'English (United Kingdom)', + 'en-us' => 'English (United States)', + 'en' => 'English (Default)', + 'eo' => 'Esperanto', + 'es' => 'Español', + 'et' => 'Eesti', + 'fi-fi' => 'Suomi', + 'fr' => 'Français', + 'hu' => 'Magyar', + 'is' => 'Íslenska', + 'it' => 'Italiano', + 'ja' => '日本語', + 'nb-no' => 'Norsk bokmål', + 'nl' => 'Nederlands', + 'pl' => 'Polski', + 'pt-br' => 'Português Brasileiro', + 'ro' => 'Română', + 'ru' => 'Русский', + 'sv' => 'Svenska', + 'zh-cn' => '简体中文', + ]; /** * A string indicating the current language used for translation: @@ -351,33 +379,6 @@ class L10n { $langs = []; $strings_file_paths = glob('view/lang/*/strings.php'); - $lang_names = [ - 'ar' => 'العربية', - 'bg' => 'Български', - 'ca' => 'Català', - 'cs' => 'Česky', - 'de' => 'Deutsch', - 'en-gb' => 'English (United Kingdom)', - 'en-us' => 'English (United States)', - 'en' => 'English (Default)', - 'eo' => 'Esperanto', - 'es' => 'Español', - 'et' => 'Eesti', - 'fi-fi' => 'Suomi', - 'fr' => 'Français', - 'hu' => 'Magyar', - 'is' => 'Íslenska', - 'it' => 'Italiano', - 'ja' => '日本語', - 'nb-no' => 'Norsk bokmål', - 'nl' => 'Nederlands', - 'pl' => 'Polski', - 'pt-br' => 'Português Brasileiro', - 'ro' => 'Română', - 'ru' => 'Русский', - 'sv' => 'Svenska', - 'zh-cn' => '简体中文', - ]; if (is_array($strings_file_paths) && count($strings_file_paths)) { if (!in_array('view/lang/en/strings.php', $strings_file_paths)) { @@ -386,7 +387,7 @@ class L10n asort($strings_file_paths); foreach ($strings_file_paths as $strings_file_path) { $path_array = explode('/', $strings_file_path); - $langs[$path_array[2]] = isset($lang_names[$path_array[2]]) ? $lang_names[$path_array[2]] : $path_array[2]; + $langs[$path_array[2]] = self::LANG_NAMES[$path_array[2]] ?? $path_array[2]; } } return $langs; From 5fcb3e490121fedb2146a3d0a14f26ed6b7502a5 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 23 Jan 2022 20:08:33 +0100 Subject: [PATCH 3/5] Remove unused field --- src/Core/L10n.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 40aa24732..8f6b093f2 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -25,7 +25,6 @@ use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Database\Database; use Friendica\Util\Strings; -use Psr\Log\LoggerInterface; /** * Provide Language, Translation, and Localization functions to the application @@ -85,15 +84,9 @@ class L10n */ private $dba; - /** - * @var LoggerInterface - */ - private $logger; - - public function __construct(IManageConfigValues $config, Database $dba, LoggerInterface $logger, IHandleSessions $session, array $server, array $get) + public function __construct(IManageConfigValues $config, Database $dba, IHandleSessions $session, array $server, array $get) { $this->dba = $dba; - $this->logger = $logger; $this->loadTranslationTable(L10n::detectLanguage($server, $get, $config->get('system', 'language', self::DEFAULT))); $this->setSessionVariable($session); From 71c7669066dc4a1992ee03520ea80593cb01623a Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 23 Jan 2022 20:08:48 +0100 Subject: [PATCH 4/5] Fix config usage during install process --- src/Core/Config/Repository/Config.php | 10 +++++++--- src/Core/PConfig/Repository/PConfig.php | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Core/Config/Repository/Config.php b/src/Core/Config/Repository/Config.php index 6efeb7f7c..72e7fa272 100644 --- a/src/Core/Config/Repository/Config.php +++ b/src/Core/Config/Repository/Config.php @@ -21,6 +21,7 @@ namespace Friendica\Core\Config\Repository; +use Friendica\App\Mode; use Friendica\Core\Config\Exception\ConfigPersistenceException; use Friendica\Core\Config\Util\ValueConversion; use Friendica\Database\Database; @@ -32,10 +33,13 @@ class Config { /** @var Database */ protected $db; + /** @var Mode */ + protected $mode; - public function __construct(Database $db) + public function __construct(Database $db, Mode $mode) { - $this->db = $db; + $this->db = $db; + $this->mode = $mode; } protected static $table_name = 'config'; @@ -47,7 +51,7 @@ class Config */ public function isConnected(): bool { - return $this->db->isConnected(); + return $this->db->isConnected() && !$this->mode->isInstall(); } /** diff --git a/src/Core/PConfig/Repository/PConfig.php b/src/Core/PConfig/Repository/PConfig.php index 50637135f..516a60fa9 100644 --- a/src/Core/PConfig/Repository/PConfig.php +++ b/src/Core/PConfig/Repository/PConfig.php @@ -21,6 +21,7 @@ namespace Friendica\Core\PConfig\Repository; +use Friendica\App\Mode; use Friendica\Core\Config\Util\ValueConversion; use Friendica\Core\PConfig\Exception\PConfigPersistenceException; use Friendica\Database\Database; @@ -34,10 +35,13 @@ class PConfig /** @var Database */ protected $db; + /** @var Mode */ + protected $mode; - public function __construct(Database $db) + public function __construct(Database $db, Mode $mode) { - $this->db = $db; + $this->db = $db; + $this->mode = $mode; } /** @@ -47,7 +51,7 @@ class PConfig */ public function isConnected(): bool { - return $this->db->isConnected(); + return $this->db->isConnected() & !$this->mode->isInstall(); } /** From 7ec4d42461f6fb8397e55df27a83c889c31c7f6d Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 23 Jan 2022 20:29:46 +0100 Subject: [PATCH 5/5] Fix test --- tests/src/Core/Storage/Repository/StorageManagerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/Core/Storage/Repository/StorageManagerTest.php b/tests/src/Core/Storage/Repository/StorageManagerTest.php index 6e3682189..a366dca9c 100644 --- a/tests/src/Core/Storage/Repository/StorageManagerTest.php +++ b/tests/src/Core/Storage/Repository/StorageManagerTest.php @@ -22,6 +22,7 @@ namespace Friendica\Test\src\Core\Storage\Repository; use Dice\Dice; +use Friendica\App\Mode; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Type\PreloadConfig; use Friendica\Core\Hook; @@ -86,7 +87,7 @@ class StorageManagerTest extends DatabaseTest $this->dba = new StaticDatabase($configCache, $profiler, $this->logger); - $configModel = new Repository\Config($this->dba); + $configModel = new Repository\Config($this->dba, new Mode(Mode::DBCONFIGAVAILABLE)); $this->config = new PreloadConfig($configCache, $configModel); $this->config->set('storage', 'name', 'Database'); $this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER)->url());