mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-16 07:11:19 +08:00
dropped locale option
This commit is contained in:
@ -597,18 +597,14 @@ class BaseArrayHelper
|
|||||||
* - lastWordConnector: The sign or word used to join the last element in arrays with
|
* - lastWordConnector: The sign or word used to join the last element in arrays with
|
||||||
* three or more elements. By default ', and '.
|
* three or more elements. By default ', and '.
|
||||||
*
|
*
|
||||||
* - locale: If i18n is available, you can set a locale and use the traslation file defined
|
|
||||||
* on the path 'messages/yii.php'.By default language defined in configuration file.
|
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function sentence($array, $options = [])
|
public static function sentence($array, $options = [])
|
||||||
{
|
{
|
||||||
$default_options = [
|
$default_options = [
|
||||||
'wordsConnector' => ', ',
|
'wordsConnector' => ', ',
|
||||||
'twoWordsConnector' => ' and ',
|
'twoWordsConnector' => ' and ',
|
||||||
'lastWordConnector' => ', and ',
|
'lastWordConnector' => ', and ',
|
||||||
'locale' => Yii::$app->language
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$options = array_merge($default_options, $options);
|
$options = array_merge($default_options, $options);
|
||||||
@ -621,9 +617,9 @@ class BaseArrayHelper
|
|||||||
case 1:
|
case 1:
|
||||||
return $array[0];
|
return $array[0];
|
||||||
case 2:
|
case 2:
|
||||||
return $array[0] . \Yii::t('yii', $options['twoWordsConnector'], [], $options['locale']) . $array[1];
|
return $array[0] . $options['twoWordsConnector'] . $array[1];
|
||||||
default:
|
default:
|
||||||
return implode($options['wordsConnector'], array_slice($array, 0, -1)) . \Yii::t('yii', $options['lastWordConnector'], [], $options['locale']) . $array[$count - 1];
|
return implode($options['wordsConnector'], array_slice($array, 0, -1)) . $options['lastWordConnector'] . $array[$count - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user