From: Kaldari Date: Tue, 17 Jul 2012 20:37:17 +0000 (-0700) Subject: Making listToText() not break if passed a 1-item list. X-Git-Tag: 1.31.0-rc.0~22926^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22lang_raccourcis%22%2C%22module=%24nom_module%22%29%20.%20%22?a=commitdiff_plain;h=e476f5f432412f1e94c1dcb7091f1757986457e2;p=lhc%2Fweb%2Fwiklou.git Making listToText() not break if passed a 1-item list. Change-Id: I25f36d25a106e2e024d4de334b0396f95792d72b --- diff --git a/languages/Language.php b/languages/Language.php index 430209d57c..7d1f8e7706 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2996,6 +2996,7 @@ class Language { * Take a list of strings and build a locale-friendly comma-separated * list, using the local comma-separator message. * The last two strings are chained with an "and". + * NOTE: This function will only work with standard numeric array keys (0, 1, 2…) * * @param $l Array * @return string @@ -3003,7 +3004,10 @@ class Language { function listToText( array $l ) { $s = ''; $m = count( $l ) - 1; - if ( $m == 1 ) { + + if ( $m === 0 ) { + return $l[0]; + } elseif ( $m === 1 ) { return $l[0] . $this->getMessageFromDB( 'and' ) . $this->getMessageFromDB( 'word-separator' ) . $l[1]; } else { for ( $i = $m; $i >= 0; $i-- ) {