]> git.mxchange.org Git - friendica.git/blobdiff - include/pgettext.php
The url detection in BBCode is too greedy
[friendica.git] / include / pgettext.php
index ae1ce009c11765654e3d4101462a3fb04abd2dee..fa3260cb1a23eabbba418ecd80d6ea4f1d344104 100644 (file)
@@ -14,18 +14,17 @@ use Friendica\Core\Config;
 
 require_once "include/dba.php";
 
-if (! function_exists('get_browser_language')) {
 /**
  * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header
  */
 function get_browser_language() {
 
+       $lang_list = [];
        if (x($_SERVER, 'HTTP_ACCEPT_LANGUAGE')) {
                // break up string into pieces (languages and q factors)
                preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
                        $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
 
-               $lang_list = [];
                if (count($lang_parse[1])) {
                        // go through the list of prefered languages and add a generic language
                        // for sub-linguas (e.g. de-ch will add de) if not already in array
@@ -42,8 +41,7 @@ function get_browser_language() {
        }
 
        // check if we have translations for the preferred languages and pick the 1st that has
-       for ($i = 0; $i < count($lang_list); $i++) {
-               $lang = $lang_list[$i];
+       foreach ($lang_list as $lang) {
                if ($lang === 'en' || (file_exists("view/lang/$lang") && is_dir("view/lang/$lang"))) {
                        $preferred = $lang;
                        break;
@@ -55,7 +53,7 @@ function get_browser_language() {
 
        // in case none matches, get the system wide configured language, or fall back to English
        return Config::get('system', 'language', 'en');
-}}
+}
 
 
 function push_lang($language) {
@@ -70,7 +68,7 @@ function push_lang($language) {
        if (isset($a->strings) && count($a->strings)) {
                $a->stringsave = $a->strings;
        }
-       $a->strings = array();
+       $a->strings = [];
        load_translation_table($language);
        $lang = $language;
 }
@@ -85,7 +83,7 @@ function pop_lang() {
        if (isset($a->stringsave)) {
                $a->strings = $a->stringsave;
        } else {
-               $a->strings = array();
+               $a->strings = [];
        }
 
        $lang = $a->langsave;
@@ -93,21 +91,20 @@ function pop_lang() {
 
 // l
 
-if (! function_exists('load_translation_table')) {
 /**
  * load string translation table for alternate language
  *
- * first plugin strings are loaded, then globals
+ * first addon strings are loaded, then globals
  *
  * @param string $lang language code to load
  */
 function load_translation_table($lang) {
        $a = get_app();
 
-       $a->strings = array();
-       // load enabled plugins strings
-       $plugins = dba::select('addon', array('name'), array('installed' => true));
-       while ($p = dba::fetch($plugins)) {
+       $a->strings = [];
+       // load enabled addons strings
+       $addons = dba::select('addon', ['name'], ['installed' => true]);
+       while ($p = dba::fetch($addons)) {
                $name = $p['name'];
                if (file_exists("addon/$name/lang/$lang/strings.php")) {
                        include("addon/$name/lang/$lang/strings.php");
@@ -118,7 +115,7 @@ function load_translation_table($lang) {
                include("view/lang/$lang/strings.php");
        }
 
-}}
+}
 
 /**
  * @brief Return the localized version of the provided string with optional string interpolation
@@ -219,7 +216,7 @@ function string_plural_select_default($n)
  * @return array
  */
 function get_available_languages() {
-       $langs = array();
+       $langs = [];
        $strings_file_paths = glob('view/lang/*/strings.php');
 
        if (is_array($strings_file_paths) && count($strings_file_paths)) {