mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Improve toList to allow localization
This commit is contained in:
parent
7ea6626a15
commit
53a544d9f0
2 changed files with 13 additions and 10 deletions
|
@ -672,15 +672,18 @@ class String {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a comma separated list where the last two items are joined with 'and', forming natural English
|
||||
* Creates a comma separated list where the last two items are joined with 'and', forming natural English.
|
||||
*
|
||||
* @param array $list The list to be joined
|
||||
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'
|
||||
* @param string $separator The separator used to join all the other items together. Defaults to ', '
|
||||
* @param array $list The list to be joined.
|
||||
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'.
|
||||
* @param string $separator The separator used to join all the other items together. Defaults to ', '.
|
||||
* @return string The glued together string.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toList
|
||||
*/
|
||||
public static function toList($list, $and = 'and', $separator = ', ') {
|
||||
public static function toList($list, $and = null, $separator = ', ') {
|
||||
if ($and === null) {
|
||||
$and = __d('cake', 'and');
|
||||
}
|
||||
if (count($list) > 1) {
|
||||
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
|
||||
}
|
||||
|
|
|
@ -329,16 +329,16 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a comma separated list where the last two items are joined with 'and', forming natural English
|
||||
* Creates a comma separated list where the last two items are joined with 'and', forming natural English.
|
||||
*
|
||||
* @param array $list The list to be joined
|
||||
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'
|
||||
* @param string $separator The separator used to join all the other items together. Defaults to ', '
|
||||
* @param array $list The list to be joined.
|
||||
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'.
|
||||
* @param string $separator The separator used to join all the other items together. Defaults to ', '.
|
||||
* @return string The glued together string.
|
||||
* @see String::toList()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toList
|
||||
*/
|
||||
public function toList($list, $and = 'and', $separator = ', ') {
|
||||
public function toList($list, $and = null, $separator = ', ') {
|
||||
return $this->_engine->toList($list, $and, $separator);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue