]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/L10n.php
Merge pull request #12322 from annando/api-rules
[friendica.git] / src / Core / L10n.php
index 8f6b093f2d8cf3c561fc723d8030ce6619ec96fa..a74f18fa6bd45ae48827c44e91e2e4bc67d14b3c 100644 (file)
@@ -40,6 +40,7 @@ class L10n
                'bg'    => 'Български',
                'ca'    => 'Català',
                'cs'    => 'Česky',
+               'da-dk' => 'Dansk (Danmark)',
                'de'    => 'Deutsch',
                'en-gb' => 'English (United Kingdom)',
                'en-us' => 'English (United States)',
@@ -49,6 +50,7 @@ class L10n
                'et'    => 'Eesti',
                'fi-fi' => 'Suomi',
                'fr'    => 'Français',
+               'gd'    => 'Gàidhlig',
                'hu'    => 'Magyar',
                'is'    => 'Íslenska',
                'it'    => 'Italiano',
@@ -127,7 +129,7 @@ class L10n
        private function setLangFromSession(IHandleSessions $session)
        {
                if ($session->get('language') !== $this->lang) {
-                       $this->loadTranslationTable($session->get('language'));
+                       $this->loadTranslationTable($session->get('language') ?? $this->lang);
                }
        }
 
@@ -139,10 +141,10 @@ class L10n
         * Uses an App object shim since all the strings files refer to $a->strings
         *
         * @param string $lang language code to load
-        *
+        * @return void
         * @throws \Exception
         */
-       private function loadTranslationTable($lang)
+       private function loadTranslationTable(string $lang)
        {
                $lang = Strings::sanitizeFilePathItem($lang);
 
@@ -182,14 +184,14 @@ class L10n
         *
         * @return string The two-letter language code
         */
-       public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT)
+       public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT): string
        {
                $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)
@@ -268,7 +270,7 @@ class L10n
         *
         * @return string
         */
-       public function t($s, ...$vars)
+       public function t(string $s, ...$vars): string
        {
                if (empty($s)) {
                        return '';
@@ -302,11 +304,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)
+       public function tt(string $singular, string $plural, int $count, ...$vars): string
        {
                $s = null;
 
@@ -339,7 +342,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;
        }
@@ -351,7 +356,7 @@ class L10n
         *
         * @return bool
         */
-       private function stringPluralSelectDefault($n)
+       private function stringPluralSelectDefault(int $n): bool
        {
                return $n != 1;
        }
@@ -368,7 +373,7 @@ class L10n
         *
         * @return array
         */
-       public static function getAvailableLanguages()
+       public static function getAvailableLanguages(): array
        {
                $langs              = [];
                $strings_file_paths = glob('view/lang/*/strings.php');
@@ -390,10 +395,9 @@ class L10n
         * Translate days and months names.
         *
         * @param string $s String with day or month name.
-        *
         * @return string Translated string.
         */
-       public function getDay($s)
+       public function getDay(string $s): string
        {
                $ret = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
                        [$this->t('Monday'), $this->t('Tuesday'), $this->t('Wednesday'), $this->t('Thursday'), $this->t('Friday'), $this->t('Saturday'), $this->t('Sunday')],
@@ -410,10 +414,9 @@ class L10n
         * Translate short days and months names.
         *
         * @param string $s String with short day or month name.
-        *
         * @return string Translated string.
         */
-       public function getDayShort($s)
+       public function getDayShort(string $s): string
        {
                $ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                        [$this->t('Mon'), $this->t('Tue'), $this->t('Wed'), $this->t('Thu'), $this->t('Fri'), $this->t('Sat'), $this->t('Sun')],
@@ -426,32 +429,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()
-       {
-               // 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
         *
@@ -460,7 +437,7 @@ class L10n
         * @return static A new L10n instance
         * @throws \Exception
         */
-       public function withLang(string $lang)
+       public function withLang(string $lang): L10n
        {
                // Don't create a new instance for same language
                if ($lang === $this->lang) {