Merge pull request #11141 from urbalazs/language-names

Add native language names to language selector & fix config during install
This commit is contained in:
Philipp 2022-01-23 20:55:40 +01:00 committed by GitHub
commit 3d8e82d95d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 18 deletions

View 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();
}
/**

View 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;

View 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();
}
/**

View 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());