aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-03 18:40:58 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-03 18:40:58 +0000
commit4b3749440c560da36b7deadcee65133062fd10a1 (patch)
tree94f92cf6b14895f754b009faa413b38a6544c9e3 /engine
parentd7df2a2b0e506b33d3c9b4c8c4013c5a5b2a73ce (diff)
downloadelgg-4b3749440c560da36b7deadcee65133062fd10a1.tar.gz
elgg-4b3749440c560da36b7deadcee65133062fd10a1.tar.bz2
Refs #1320: elgg_echo() has built-in sprintf support.
git-svn-id: http://code.elgg.org/elgg/trunk@7226 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/languages.php32
1 files changed, 27 insertions, 5 deletions
diff --git a/engine/lib/languages.php b/engine/lib/languages.php
index 3472d0d29..d34a89707 100644
--- a/engine/lib/languages.php
+++ b/engine/lib/languages.php
@@ -86,15 +86,29 @@ function get_language() {
* Given a message shortcode, 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 or the original English string
+ * @return string Either the translated string, the English string,
+ * or the original language string.
*/
-function elgg_echo($message_key, $language = "") {
+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();
}
@@ -103,12 +117,20 @@ function elgg_echo($message_key, $language = "") {
}
if (isset($CONFIG->translations[$language][$message_key])) {
- return $CONFIG->translations[$language][$message_key];
+ $string = $CONFIG->translations[$language][$message_key];
} else if (isset($CONFIG->translations["en"][$message_key])) {
- return $CONFIG->translations["en"][$message_key];
+ $string = $CONFIG->translations["en"][$message_key];
+ } else {
+ $string = $message_key;
+ }
+
+ // only pass through if we have arguments to allow backward compatibility
+ // with manual sprintf() calls.
+ if ($args) {
+ $string = vsprintf($string, $args);
}
- return $message_key;
+ return $string;
}
/**