]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/L10n.php
Merge pull request #6942 from annando/worker-fast-commands
[friendica.git] / src / Core / L10n.php
index 45b70e06258663bb1e7abb8ee784c37863d4ee95..f7ed9918ce7bd8feb139774ab2676074aed1aff9 100644 (file)
@@ -6,10 +6,6 @@ namespace Friendica\Core;
 
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
-use Friendica\Core\System;
-
-require_once 'boot.php';
-require_once 'include/dba.php';
 
 /**
  * Provide Language, Translation, and Localization functions to the application
@@ -78,6 +74,10 @@ class L10n extends BaseObject
                                }
                        }
                }
+
+               if (isset($_GET['lang'])) {
+                       $_SESSION['language'] = $_GET['lang'];
+               }
        }
 
        public static function setLangFromSession()
@@ -90,6 +90,7 @@ class L10n extends BaseObject
        /**
         * @brief Returns the preferred language from the HTTP_ACCEPT_LANGUAGE header
         * @return string The two-letter language code
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function detectLanguage()
        {
@@ -114,6 +115,10 @@ class L10n extends BaseObject
                        }
                }
 
+               if (isset($_GET['lang'])) {
+                       $lang_list = [$_GET['lang']];
+               }
+
                // check if we have translations for the preferred languages and pick the 1st that has
                foreach ($lang_list as $lang) {
                        if ($lang === 'en' || (file_exists("view/lang/$lang") && is_dir("view/lang/$lang"))) {
@@ -137,9 +142,10 @@ class L10n extends BaseObject
         *
         * If called repeatedly, it won't save the translation strings again, just load the new ones.
         *
-        * @see popLang()
+        * @see   popLang()
         * @brief Stores the current language strings and load a different language.
         * @param string $lang Language code
+        * @throws \Exception
         */
        public static function pushLang($lang)
        {
@@ -183,6 +189,7 @@ class L10n extends BaseObject
         * Uses an App object shim since all the strings files refer to $a->strings
         *
         * @param string $lang language code to load
+        * @throws \Exception
         */
        private static function loadTranslationTable($lang)
        {
@@ -265,13 +272,14 @@ class L10n extends BaseObject
         *
         * @param string $singular
         * @param string $plural
-        * @param int $count
+        * @param int    $count
         * @return string
+        * @throws \Exception
         */
        public static function tt($singular, $plural, $count)
        {
                if (!is_numeric($count)) {
-                       logger('Non numeric count called by ' . System::callstack(20));
+                       Logger::log('Non numeric count called by ' . System::callstack(20));
                }
 
                if (!self::$lang) {
@@ -310,6 +318,9 @@ class L10n extends BaseObject
 
        /**
         * Provide a fallback which will not collide with a function defined in any language file
+        *
+        * @param int $n
+        * @return bool
         */
        private static function stringPluralSelectDefault($n)
        {
@@ -344,4 +355,68 @@ class L10n extends BaseObject
                }
                return $langs;
        }
+
+       /**
+        * @brief Translate days and months names.
+        *
+        * @param string $s String with day or month name.
+        * @return string Translated string.
+        */
+       public static function getDay($s)
+       {
+               $ret = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
+                       [self::t('Monday'), self::t('Tuesday'), self::t('Wednesday'), self::t('Thursday'), self::t('Friday'), self::t('Saturday'), self::t('Sunday')],
+                       $s);
+
+               $ret = str_replace(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
+                       [self::t('January'), self::t('February'), self::t('March'), self::t('April'), self::t('May'), self::t('June'), self::t('July'), self::t('August'), self::t('September'), self::t('October'), self::t('November'), self::t('December')],
+                       $ret);
+
+               return $ret;
+       }
+
+       /**
+        * @brief Translate short days and months names.
+        *
+        * @param string $s String with short day or month name.
+        * @return string Translated string.
+        */
+       public static function getDayShort($s)
+       {
+               $ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
+                       [self::t('Mon'), self::t('Tue'), self::t('Wed'), self::t('Thu'), self::t('Fri'), self::t('Sat'), self::t('Sun')],
+                       $s);
+
+               $ret = str_replace(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
+                       [self::t('Jan'), self::t('Feb'), self::t('Mar'), self::t('Apr'), self::t('May'), ('Jun'), self::t('Jul'), self::t('Aug'), self::t('Sep'), self::t('Oct'), self::t('Nov'), self::t('Dec')],
+                       $ret);
+
+               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 static function getPokeVerbs()
+       {
+               // index is present tense verb
+               // value is array containing past tense verb, translation of present, translation of past
+               $arr = [
+                       'poke' => ['poked', self::t('poke'), self::t('poked')],
+                       'ping' => ['pinged', self::t('ping'), self::t('pinged')],
+                       'prod' => ['prodded', self::t('prod'), self::t('prodded')],
+                       'slap' => ['slapped', self::t('slap'), self::t('slapped')],
+                       'finger' => ['fingered', self::t('finger'), self::t('fingered')],
+                       'rebuff' => ['rebuffed', self::t('rebuff'), self::t('rebuffed')],
+               ];
+
+               Hook::callAll('poke_verbs', $arr);
+
+               return $arr;
+       }
 }