]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #11141 from urbalazs/language-names
authorPhilipp <admin+Github@philipp.info>
Sun, 23 Jan 2022 19:55:40 +0000 (20:55 +0100)
committerGitHub <noreply@github.com>
Sun, 23 Jan 2022 19:55:40 +0000 (20:55 +0100)
Add native language names to language selector & fix config during install

src/Core/Config/Repository/Config.php
src/Core/L10n.php
src/Core/PConfig/Repository/PConfig.php
tests/src/Core/Storage/Repository/StorageManagerTest.php

index 6efeb7f7c6702592f8aaf856ad2df2823ebfefb7..72e7fa2724669b29faa09efafa7c0381b2e05ae1 100644 (file)
@@ -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();
        }
 
        /**
index 90d4c0fe510f771f4475ff8df1fd44e1aac2e6a0..8f6b093f2d8cf3c561fc723d8030ce6619ec96fa 100644 (file)
@@ -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
@@ -35,6 +34,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:
@@ -57,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);
@@ -340,9 +361,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
         */
@@ -358,7 +380,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]] = self::LANG_NAMES[$path_array[2]] ?? $path_array[2];
                        }
                }
                return $langs;
index 50637135f6c48be0f68e0ac3a79c02e09c32ac8e..516a60fa9cd847970326d21a3b1ca56f1683b8f3 100644 (file)
@@ -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();
        }
 
        /**
index c387e265bf9529fc522484d6f53cbd1ff1db3733..cce12b790a24353c5a193ba06ab45ddc5a654c31 100644 (file)
@@ -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;
@@ -83,7 +84,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());