From d0780ccf7dd3efb5337912dcf293617bea495d2a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 22:37:51 -0400 Subject: [PATCH] Replace global $lang with system.language --- config/defaults.ini.php | 2 +- mod/help.php | 6 ++---- mod/register.php | 4 +--- mod/regmod.php | 2 -- src/Content/Text/HTML.php | 2 -- src/Core/L10n.php | 26 ++++++++++++-------------- 6 files changed, 16 insertions(+), 26 deletions(-) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index 84c039c2a0..2f1357e3aa 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -209,7 +209,7 @@ invitation_only = false jpeg_quality = 100 ; language (String) -; Admin-created user default language. +; System default languague, inluding admin-created user default language. ; Two-letters ISO 639-1 code. language = en diff --git a/mod/help.php b/mod/help.php index ef640737aa..5db74c15e8 100644 --- a/mod/help.php +++ b/mod/help.php @@ -6,13 +6,13 @@ use Friendica\App; use Friendica\Content\Nav; use Friendica\Content\Text\Markdown; +use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\System; function load_doc_file($s) { - global $lang; - if (!isset($lang)) $lang = 'en'; + $lang = Config::get('system', 'language'); $b = basename($s); $d = dirname($s); if (file_exists("$d/$lang/$b")) { @@ -30,8 +30,6 @@ function help_content(App $a) { Nav::setSelected('help'); - global $lang; - $text = ''; if ($a->argc > 1) { diff --git a/mod/register.php b/mod/register.php index 75f2ec8532..53bca68405 100644 --- a/mod/register.php +++ b/mod/register.php @@ -21,8 +21,6 @@ function register_post(App $a) { check_form_security_token_redirectOnErr('/register', 'register'); - global $lang; - $verified = 0; $blocked = 1; @@ -123,7 +121,7 @@ function register_post(App $a) dbesc(DateTimeFormat::utcNow()), intval($user['uid']), dbesc($result['password']), - dbesc($lang), + dbesc(Config::get('system', 'language')), dbesc($_POST['permonlybox']) ); diff --git a/mod/regmod.php b/mod/regmod.php index 083465984f..2a418fcda0 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -97,8 +97,6 @@ function user_deny($hash) function regmod_content(App $a) { - global $lang; - if (!local_user()) { info(L10n::t('Please login.') . EOL); $o = '

' . Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1); diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index 896db876f5..d6e699ed7b 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -549,8 +549,6 @@ class HTML public static function toPlaintext($html, $wraplength = 75, $compact = false) { - global $lang; - $message = str_replace("\r", "", $html); $doc = new DOMDocument(); diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 24be010955..2389817021 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -14,7 +14,7 @@ require_once 'include/dba.php'; * Provide Languange, Translation, and Localisation functions to the application * Localisation can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N"). */ -class L10n +class L10n extends \Friendica\BaseObject { /** * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header @@ -62,11 +62,11 @@ class L10n */ public static function pushLang($language) { - global $lang, $a; + $a = self::getApp(); - $a->langsave = $lang; + $a->langsave = Config::get('system', 'language'); - if ($language === $lang) { + if ($language === $a->langsave) { return; } @@ -75,7 +75,7 @@ class L10n } $a->strings = []; self::loadTranslationTable($language); - $lang = $language; + Config::set('system', 'language', $language); } /** @@ -83,9 +83,9 @@ class L10n */ public static function popLang() { - global $lang, $a; + $a = self::getApp(); - if ($lang === $a->langsave) { + if (Config::get('system', 'language') === $a->langsave) { return; } @@ -95,7 +95,7 @@ class L10n $a->strings = []; } - $lang = $a->langsave; + Config::set('system', 'language', $a->langsave); } /** @@ -107,7 +107,7 @@ class L10n */ public static function loadTranslationTable($lang) { - $a = get_app(); + $a = self::getApp(); $a->strings = []; // load enabled addons strings @@ -142,7 +142,7 @@ class L10n */ public static function t($s, ...$vars) { - $a = get_app(); + $a = self::getApp(); if (empty($s)) { return ''; @@ -173,7 +173,6 @@ class L10n * - L10n::tt('Like', 'Likes', $count) * - L10n::tt("%s user deleted", "%s users deleted", count($users)) * - * @global type $lang * @param string $singular * @param string $plural * @param int $count @@ -181,10 +180,9 @@ class L10n */ public static function tt($singular, $plural, $count) { - global $lang; - $a = get_app(); + $lang = Config::get('system', 'language'); - if (x($a->strings, $singular)) { + if (!empty($a->strings[$singular])) { $t = $a->strings[$singular]; if (is_array($t)) { $plural_function = 'string_plural_select_' . str_replace('-', '_', $lang); -- 2.39.5