Browse Source

Internal: Update get_lang() to use the "reserved" parameter as "strict". If the "strict" param is set to true, get_lang will return en empty string if it cannot find the given variable.

Yannick Warnier 6 years ago
parent
commit
ab28b822fd
1 changed files with 9 additions and 7 deletions
  1. 9 7
      main/inc/lib/internationalization.lib.php

+ 9 - 7
main/inc/lib/internationalization.lib.php

@@ -60,11 +60,11 @@ define('PERSON_NAME_EMAIL_ADDRESS', PERSON_NAME_WESTERN_ORDER);
 define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER);
 
 /**
- * Returns a translated (localized) string, called by its identificator.
+ * Returns a translated (localized) string, called by its ID.
  *
- * @param string $variable this is the identificator (name) of the translated string to be retrieved
- * @param string $reserved this parameter has been reserved for future use
- * @param string $language (optional)    Language indentificator. If it is omited, the current interface language is assumed.
+ * @param string $variable this is the ID (name) of the translated string to be retrieved
+ * @param bool   $strict   If variable is not found, then: if false: returns variable name with or without brackets; true: returns ''
+ * @param string $language (optional)    Language ID. If it is omitted, the current interface language is assumed.
  *
  * @return string returns the requested string in the correspondent language
  *
@@ -82,7 +82,7 @@ define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER);
  *
  * @see http://translate.chamilo.org/
  */
-function get_lang($variable, $reserved = null, $language = null)
+function get_lang($variable, $strict = false, $language = null)
 {
     // For serving some old hacks:
     // By manipulating this global variable the translation may
@@ -141,17 +141,18 @@ function get_lang($variable, $reserved = null, $language = null)
     // - from a local variable after reloading the language files - on test server mode or when requested language
     // is different than the genuine interface language.
     $read_global_variables = $is_interface_language;
+    $langvar = '';
 
     if ($read_global_variables) {
         if (isset($GLOBALS[$variable])) {
             $langvar = $GLOBALS[$variable];
         } elseif (isset($GLOBALS["lang$variable"])) {
             $langvar = $GLOBALS["lang$variable"];
-        } else {
+        } elseif (!$strict) {
             $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable;
         }
     }
-    if (empty($langvar) || !is_string($langvar)) {
+    if (empty($langvar) || !is_string($langvar) && !$strict) {
         $langvar = $show_special_markup ? SPECIAL_OPENING_TAG.$variable.SPECIAL_CLOSING_TAG : $variable;
     }
     $ret = $cache[$language][$variable] = $langvar;
@@ -168,6 +169,7 @@ function get_lang($variable, $reserved = null, $language = null)
  * @param bool $setParentLanguageName
  *
  * @return string the current language of the interface
+ * @throws Exception
  */
 function api_get_interface_language(
     $purified = false,