X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FL10n.php;h=ae0ed18c3d0a732364bfc5d53ca072f935f253cf;hb=58c8959da0ece9a23966b315310a3962542bc7f4;hp=4d538acb2faa3d7055aa4d77d673da3a91d99bdd;hpb=dfd48596d3c7092d55a37572cfa0ad21896ebcbd;p=friendica.git diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 4d538acb2f..ae0ed18c3d 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -6,12 +6,7 @@ namespace Friendica\Core; use Friendica\BaseObject; use Friendica\Database\DBA; -use Friendica\Core\Addon; -use Friendica\Core\Logger; -use Friendica\Core\System; - -require_once 'boot.php'; -require_once 'include/dba.php'; +use Friendica\Util\Strings; /** * Provide Language, Translation, and Localization functions to the application @@ -80,6 +75,10 @@ class L10n extends BaseObject } } } + + if (isset($_GET['lang'])) { + $_SESSION['language'] = $_GET['lang']; + } } public static function setLangFromSession() @@ -92,6 +91,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() { @@ -116,6 +116,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"))) { @@ -139,9 +143,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) { @@ -185,9 +190,12 @@ 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) { + $lang = Strings::sanitizeFilePathItem($lang); + if ($lang === self::$lang) { return; } @@ -198,7 +206,7 @@ class L10n extends BaseObject // load enabled addons strings $addons = DBA::select('addon', ['name'], ['installed' => true]); while ($p = DBA::fetch($addons)) { - $name = $p['name']; + $name = Strings::sanitizeFilePathItem($p['name']); if (file_exists("addon/$name/lang/$lang/strings.php")) { include "addon/$name/lang/$lang/strings.php"; } @@ -267,8 +275,9 @@ 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) { @@ -312,6 +321,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) { @@ -355,11 +367,11 @@ class L10n extends BaseObject */ public static function getDay($s) { - $ret = str_replace(['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'], + $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'], + $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); @@ -378,7 +390,7 @@ class L10n extends BaseObject [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'], + $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); @@ -389,7 +401,8 @@ class L10n extends BaseObject * Load poke verbs * * @return array index is present tense verb - * value is array containing past tense verb, translation of present, translation of past + * 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() @@ -405,7 +418,7 @@ class L10n extends BaseObject 'rebuff' => ['rebuffed', self::t('rebuff'), self::t('rebuffed')], ]; - Addon::callHooks('poke_verbs', $arr); + Hook::callAll('poke_verbs', $arr); return $arr; }