X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FL10n.php;h=3f74a408496299d3b1be0059a7c548ccd46efec3;hb=23f2bd1a2d292018c6927b149cafd278274c6d1b;hp=08296068bb91f9e4b476915764387c42fd14aad5;hpb=14bf72e4feeb91d70ad0c055c9b6620617e89452;p=friendica.git diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 08296068bb..3f74a40849 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -1,6 +1,6 @@ 'Eesti', 'fi-fi' => 'Suomi', 'fr' => 'Français', + 'gd' => 'Gàidhlig', 'hu' => 'Magyar', 'is' => 'Íslenska', 'it' => 'Italiano', @@ -84,10 +85,15 @@ class L10n * @var Database */ private $dba; + /** + * @var IManageConfigValues + */ + private $config; public function __construct(IManageConfigValues $config, Database $dba, IHandleSessions $session, array $server, array $get) { $this->dba = $dba; + $this->config = $config; $this->loadTranslationTable(L10n::detectLanguage($server, $get, $config->get('system', 'language', self::DEFAULT))); $this->setSessionVariable($session); @@ -156,9 +162,9 @@ class L10n $a->strings = []; // load enabled addons strings - $addons = $this->dba->select('addon', ['name'], ['installed' => true]); - while ($p = $this->dba->fetch($addons)) { - $name = Strings::sanitizeFilePathItem($p['name']); + $addons = array_keys($this->config->get('addons') ?? []); + foreach ($addons as $addon) { + $name = Strings::sanitizeFilePathItem($addon); if (file_exists(__DIR__ . "/../../addon/$name/lang/$lang/strings.php")) { include __DIR__ . "/../../addon/$name/lang/$lang/strings.php"; } @@ -187,10 +193,10 @@ class L10n { $lang_variable = $server['HTTP_ACCEPT_LANGUAGE'] ?? null; - $acceptedLanguages = preg_split('/,\s*/', $lang_variable); - - if (empty($acceptedLanguages)) { + if (empty($lang_variable)) { $acceptedLanguages = []; + } else { + $acceptedLanguages = preg_split('/,\s*/', $lang_variable); } // Add get as absolute quality accepted language (except this language isn't valid) @@ -269,7 +275,7 @@ class L10n * * @return string */ - public function t(array $s, ...$vars): string + public function t(string $s, ...$vars): string { if (empty($s)) { return ''; @@ -303,11 +309,12 @@ class L10n * @param string $singular * @param string $plural * @param int $count + * @param array $vars Variables to interpolate in the translation string * * @return string * @throws \Exception */ - public function tt(string $singular, string $plural, int $count): string + public function tt(string $singular, string $plural, int $count, ...$vars): string { $s = null; @@ -340,7 +347,9 @@ class L10n $s = $singular; } - $s = @sprintf($s, $count); + // We mute errors here because the translation strings may not be referencing the count at all, + // but we still have to try the interpolation just in case it is indeed referenced. + $s = @sprintf($s, $count, ...$vars); return $s; } @@ -425,32 +434,6 @@ class L10n return $ret; } - /** - * Load poke verbs - * - * @return array index is present tense verb - * value is array containing past tense verb, translation of present, translation of past - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - * @hook poke_verbs pokes array - */ - public function getPokeVerbs(): array - { - // index is present tense verb - // value is array containing past tense verb, translation of present, translation of past - $arr = [ - 'poke' => ['poked', $this->t('poke'), $this->t('poked')], - 'ping' => ['pinged', $this->t('ping'), $this->t('pinged')], - 'prod' => ['prodded', $this->t('prod'), $this->t('prodded')], - 'slap' => ['slapped', $this->t('slap'), $this->t('slapped')], - 'finger' => ['fingered', $this->t('finger'), $this->t('fingered')], - 'rebuff' => ['rebuffed', $this->t('rebuff'), $this->t('rebuffed')], - ]; - - Hook::callAll('poke_verbs', $arr); - - return $arr; - } - /** * Creates a new L10n instance based on the given langauge *