/** * Given a message key, returns an appropriately translated full-text string * * @param string $message_key The short message code * @param array $args An array of arguments to pass through vsprintf(). * @param string $language Optionally, the standard language code * (defaults to site/user default, then English) * * @return string Either the translated string, the English string, * or the original language string. */ function translate($message_key, $args = array(), $language = "") { static $CURRENT_LANGUAGE; // old param order is deprecated if (!is_array($args)) { elgg_deprecated_notice('As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.', 1.8); $language = $args; $args = array(); } if (!isset($GLOBALS['_ELGG']->translations)) { // this means we probably had an exception before translations were initialized $this->registerTranslations($this->defaultPath); } if (!$CURRENT_LANGUAGE) { $CURRENT_LANGUAGE = $this->getLanguage(); } if (!$language) { $language = $CURRENT_LANGUAGE; } if (!isset($GLOBALS['_ELGG']->translations[$language])) { // The language being requested is not the same as the language of the // logged in user, so we will have to load it separately. (Most likely // we're sending a notification and the recipient is using a different // language than the logged in user.) _elgg_load_translations_for_language($language); } if (isset($GLOBALS['_ELGG']->translations[$language][$message_key])) { $string = $GLOBALS['_ELGG']->translations[$language][$message_key]; } else { if (isset($GLOBALS['_ELGG']->translations["en"][$message_key])) { $string = $GLOBALS['_ELGG']->translations["en"][$message_key]; _elgg_services()->logger->notice(sprintf('Missing %s translation for "%s" language key', $language, $message_key)); } else { $string = $message_key; _elgg_services()->logger->notice(sprintf('Missing English translation for "%s" language key', $message_key)); } } // only pass through if we have arguments to allow backward compatibility // with manual sprintf() calls. if ($args) { $string = vsprintf($string, $args); } return $string; }
/** * Given a message key, returns an appropriately translated full-text string * * @param string $message_key The short message code * @param array $args An array of arguments to pass through vsprintf(). * @param string $language Optionally, the standard language code * (defaults to site/user default, then English) * * @return string Either the translated string, the English string, * or the original language string. */ function elgg_echo($message_key, $args = array(), $language = "") { global $CONFIG; static $CURRENT_LANGUAGE; // old param order is deprecated if (!is_array($args)) { elgg_deprecated_notice('As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.', 1.8); $language = $args; $args = array(); } if (!$CURRENT_LANGUAGE) { $CURRENT_LANGUAGE = get_language(); } if (!$language) { $language = $CURRENT_LANGUAGE; } if (!isset($CONFIG->translations[$language])) { // The language being requested is not the same as the language of the // logged in user, so we will have to load it separately. (Most likely // we're sending a notification and the recipient is using a different // language than the logged in user.) _elgg_load_translations_for_language($language); } if (isset($CONFIG->translations[$language][$message_key])) { $string = $CONFIG->translations[$language][$message_key]; } else { if (isset($CONFIG->translations["en"][$message_key])) { $string = $CONFIG->translations["en"][$message_key]; elgg_log(sprintf('Missing %s translation for "%s" language key', $language, $message_key), 'NOTICE'); } else { $string = $message_key; elgg_log(sprintf('Missing English translation for "%s" language key', $message_key), 'NOTICE'); } } // only pass through if we have arguments to allow backward compatibility // with manual sprintf() calls. if ($args) { $string = vsprintf($string, $args); } return $string; }