/** * Retrieves an internationalized string * This function will return one of (in order of preference): * 1. The string in the current user's preferred language (if defined) * 2. The string in English * * @param mixed $p_string string or array of string with term keys * * @internal Revisions: * 20070501 - franciscom - added TL_LOCALIZE_TAG in order to * improve label management for custom fields */ function lang_get($p_string, $p_lang = null, $bDontFireEvents = false) { if ($p_string == '' || is_null($p_string)) { return $p_string; } $t_lang = $p_lang; if (null === $t_lang) { $t_lang = isset($_SESSION['locale']) ? $_SESSION['locale'] : TL_DEFAULT_LOCALE; } lang_ensure_loaded($t_lang); global $g_lang_strings; $loc_str = null; $missingL18N = false; $englishSolutionFound = false; if (isset($g_lang_strings[$t_lang][$p_string])) { $loc_str = $g_lang_strings[$t_lang][$p_string]; } else { if ($t_lang != 'en_GB') { // force load of english strings lang_ensure_loaded('en_GB'); } if (isset($g_lang_strings['en_GB'][$p_string])) { $missingL18N = true; $englishSolutionFound = true; $loc_str = $g_lang_strings['en_GB'][$p_string]; } } $the_str = $loc_str; $missingL18N = is_null($loc_str) || $missingL18N; if (!is_null($loc_str)) { $stringFileCharset = "ISO-8859-1"; if (isset($g_lang_strings[$t_lang]['STRINGFILE_CHARSET'])) { $stringFileCharset = $g_lang_strings[$t_lang]['STRINGFILE_CHARSET']; } if ($stringFileCharset != TL_TPL_CHARSET) { $the_str = iconv($stringFileCharset, TL_TPL_CHARSET, $loc_str); } } if ($missingL18N) { // if( $t_lang != 'en_GB' ) // { // // force load of english strings // lang_ensure_loaded('en_GB'); // } if (!$bDontFireEvents) { // 20100823 - franciscom // When testing with a user with locale = italian, found // 1. missing localized string was replaced with version present on english strings // 2. no log written to event viewer // 3. detected a call to lang_get() with language en_GB // $msg = sprintf("string '%s' is not localized for locale '%s'", $p_string, $t_lang); logWarningEvent($msg, "LOCALIZATION"); } if (!$englishSolutionFound) { $the_str = TL_LOCALIZE_TAG . $p_string; } } return $the_str; }
function lang_get($p_string, $p_lang = null) { $t_lang = $p_lang; if (null === $p_lang) { $t_lang = isset($_SESSION['locale']) ? $_SESSION['locale'] : null; } if (null === $t_lang) { $t_lang = DASHBOARD_DEFAULT_LOCALE; } lang_ensure_loaded($t_lang); global $g_lang_strings; $the_str = isset($g_lang_strings[$t_lang][$p_string]) ? $g_lang_strings[$t_lang][$p_string] : "LOCALIZE: " . $p_string; if (DASHBAORD_CHARSET == 'UTF-8') { return utf8_encode($the_str); } else { return $the_str; } }
/** * Get language: * - If found, return the appropriate string (as lang_get()). * - If not found, no default supplied, return the supplied string as is. * - If not found, default supplied, return default. * @param string $p_string * @param string $p_default * @param string $p_lang * @return string */ function lang_get_defaulted($p_string, $p_default = null, $p_lang = null) { $t_lang = $p_lang; if (null === $t_lang) { $t_lang = lang_get_current(); } # Now we'll make sure that the requested language is loaded lang_ensure_loaded($t_lang); if (lang_exists($p_string, $t_lang)) { return lang_get($p_string); } else { if (null === $p_default) { return $p_string; } else { return $p_default; } } }
function lang_exists($p_string) { global $g_lang_strings; lang_ensure_loaded(); return isset($g_lang_strings[$p_string]); }
/** * Retrieves an internationalized string * This function will return one of (in order of preference): * 1. The string in the current user's preferred language (if defined) * 2. The string in English * * @param mixed $p_string string or array of string with term keys * * @internal revisions */ function lang_get($p_string, $p_lang = null, $bDontFireEvents = false) { if ($p_string == '' || is_null($p_string)) { return $p_string; } $t_lang = $p_lang; if (null === $t_lang) { $t_lang = isset($_SESSION['locale']) ? $_SESSION['locale'] : TL_DEFAULT_LOCALE; } lang_ensure_loaded($t_lang); global $g_lang_strings; $loc_str = null; $missingL18N = false; $englishSolutionFound = false; if (isset($g_lang_strings[$t_lang][$p_string])) { $loc_str = $g_lang_strings[$t_lang][$p_string]; } else { if ($t_lang != 'en_GB') { // force load of english strings lang_ensure_loaded('en_GB'); } if (isset($g_lang_strings['en_GB'][$p_string])) { $missingL18N = true; $englishSolutionFound = true; $loc_str = $g_lang_strings['en_GB'][$p_string]; } } $the_str = $loc_str; $missingL18N = is_null($loc_str) || $missingL18N; if (!is_null($loc_str)) { $stringFileCharset = "ISO-8859-1"; if (isset($g_lang_strings[$t_lang]['STRINGFILE_CHARSET'])) { $stringFileCharset = $g_lang_strings[$t_lang]['STRINGFILE_CHARSET']; } if ($stringFileCharset != TL_TPL_CHARSET) { $the_str = iconv($stringFileCharset, TL_TPL_CHARSET, $loc_str); } } if ($missingL18N) { if ($englishSolutionFound) { $addMsg = ' - using en_GB'; } else { $the_str = TL_LOCALIZE_TAG . $p_string; $addMsg = ''; } if (!$bDontFireEvents) { // When testing with a user with locale = italian, found // 1. missing localized string was replaced with version present on english strings // 2. no log written to event viewer // 3. detected a call to lang_get() with language en_GB // // try to report just one per user session // 20130913 - missing check for $_SESSION existence create a mess with language detection // via browser if (isset($_SESSION) && !isset($_SESSION['missingL18N'][$p_string])) { $msg = sprintf("string '%s' is not localized for locale '%s' {$addMsg}", $p_string, $t_lang); $_SESSION['missingL18N'][$p_string] = $p_string; logL18NWarningEvent($msg, "LOCALIZATION"); } } } return $the_str; }