Replace global $lang with system.language

This commit is contained in:
Hypolite Petovan 2018-07-09 22:37:51 -04:00
parent adacf421a6
commit d0780ccf7d
6 changed files with 16 additions and 26 deletions

View File

@ -209,7 +209,7 @@ invitation_only = false
jpeg_quality = 100 jpeg_quality = 100
; language (String) ; language (String)
; Admin-created user default language. ; System default languague, inluding admin-created user default language.
; Two-letters ISO 639-1 code. ; Two-letters ISO 639-1 code.
language = en language = en

View File

@ -6,13 +6,13 @@
use Friendica\App; use Friendica\App;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Text\Markdown; use Friendica\Content\Text\Markdown;
use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
function load_doc_file($s) function load_doc_file($s)
{ {
global $lang; $lang = Config::get('system', 'language');
if (!isset($lang)) $lang = 'en';
$b = basename($s); $b = basename($s);
$d = dirname($s); $d = dirname($s);
if (file_exists("$d/$lang/$b")) { if (file_exists("$d/$lang/$b")) {
@ -30,8 +30,6 @@ function help_content(App $a)
{ {
Nav::setSelected('help'); Nav::setSelected('help');
global $lang;
$text = ''; $text = '';
if ($a->argc > 1) { if ($a->argc > 1) {

View File

@ -21,8 +21,6 @@ function register_post(App $a)
{ {
check_form_security_token_redirectOnErr('/register', 'register'); check_form_security_token_redirectOnErr('/register', 'register');
global $lang;
$verified = 0; $verified = 0;
$blocked = 1; $blocked = 1;
@ -123,7 +121,7 @@ function register_post(App $a)
dbesc(DateTimeFormat::utcNow()), dbesc(DateTimeFormat::utcNow()),
intval($user['uid']), intval($user['uid']),
dbesc($result['password']), dbesc($result['password']),
dbesc($lang), dbesc(Config::get('system', 'language')),
dbesc($_POST['permonlybox']) dbesc($_POST['permonlybox'])
); );

View File

@ -97,8 +97,6 @@ function user_deny($hash)
function regmod_content(App $a) function regmod_content(App $a)
{ {
global $lang;
if (!local_user()) { if (!local_user()) {
info(L10n::t('Please login.') . EOL); info(L10n::t('Please login.') . EOL);
$o = '<br /><br />' . Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1); $o = '<br /><br />' . Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1);

View File

@ -549,8 +549,6 @@ class HTML
public static function toPlaintext($html, $wraplength = 75, $compact = false) public static function toPlaintext($html, $wraplength = 75, $compact = false)
{ {
global $lang;
$message = str_replace("\r", "", $html); $message = str_replace("\r", "", $html);
$doc = new DOMDocument(); $doc = new DOMDocument();

View File

@ -14,7 +14,7 @@ require_once 'include/dba.php';
* Provide Languange, Translation, and Localisation functions to the application * 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"). * 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 * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header
@ -62,11 +62,11 @@ class L10n
*/ */
public static function pushLang($language) 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; return;
} }
@ -75,7 +75,7 @@ class L10n
} }
$a->strings = []; $a->strings = [];
self::loadTranslationTable($language); self::loadTranslationTable($language);
$lang = $language; Config::set('system', 'language', $language);
} }
/** /**
@ -83,9 +83,9 @@ class L10n
*/ */
public static function popLang() public static function popLang()
{ {
global $lang, $a; $a = self::getApp();
if ($lang === $a->langsave) { if (Config::get('system', 'language') === $a->langsave) {
return; return;
} }
@ -95,7 +95,7 @@ class L10n
$a->strings = []; $a->strings = [];
} }
$lang = $a->langsave; Config::set('system', 'language', $a->langsave);
} }
/** /**
@ -107,7 +107,7 @@ class L10n
*/ */
public static function loadTranslationTable($lang) public static function loadTranslationTable($lang)
{ {
$a = get_app(); $a = self::getApp();
$a->strings = []; $a->strings = [];
// load enabled addons strings // load enabled addons strings
@ -142,7 +142,7 @@ class L10n
*/ */
public static function t($s, ...$vars) public static function t($s, ...$vars)
{ {
$a = get_app(); $a = self::getApp();
if (empty($s)) { if (empty($s)) {
return ''; return '';
@ -173,7 +173,6 @@ class L10n
* - L10n::tt('Like', 'Likes', $count) * - L10n::tt('Like', 'Likes', $count)
* - L10n::tt("%s user deleted", "%s users deleted", count($users)) * - L10n::tt("%s user deleted", "%s users deleted", count($users))
* *
* @global type $lang
* @param string $singular * @param string $singular
* @param string $plural * @param string $plural
* @param int $count * @param int $count
@ -181,10 +180,9 @@ class L10n
*/ */
public static function tt($singular, $plural, $count) public static function tt($singular, $plural, $count)
{ {
global $lang; $lang = Config::get('system', 'language');
$a = get_app();
if (x($a->strings, $singular)) { if (!empty($a->strings[$singular])) {
$t = $a->strings[$singular]; $t = $a->strings[$singular];
if (is_array($t)) { if (is_array($t)) {
$plural_function = 'string_plural_select_' . str_replace('-', '_', $lang); $plural_function = 'string_plural_select_' . str_replace('-', '_', $lang);