Permalink
Browse files

MINOR Switching _t() calls from sprintf() to using injection paramete…

…rs (#7170)
  • Loading branch information...
1 parent e949b6f commit 7b18d9d0da94a8364fbe528f816838002c5bd157 @chillu chillu committed May 1, 2012
@@ -70,17 +70,17 @@ function doImport($data, $form) {
// result message
$msgArr = array();
- if($result->CreatedCount()) $msgArr[] = sprintf(
- _t('GroupImportForm.ResultCreated', 'Created %d groups'),
- $result->CreatedCount()
+ if($result->CreatedCount()) $msgArr[] = _t(
+ 'GroupImportForm.ResultCreated', 'Created {count} groups',
+ array('count' => $result->CreatedCount())
);
- if($result->UpdatedCount()) $msgArr[] = sprintf(
- _t('GroupImportForm.ResultUpdated', 'Updated %d groups'),
- $result->UpdatedCount()
+ if($result->UpdatedCount()) $msgArr[] = _t(
+ 'GroupImportForm.ResultUpdated', 'Updated %d groups',
+ array('count' => $result->UpdatedCount())
);
- if($result->DeletedCount()) $msgArr[] = sprintf(
- _t('GroupImportForm.ResultDeleted', 'Deleted %d groups'),
- $result->DeletedCount()
+ if($result->DeletedCount()) $msgArr[] = _t(
+ 'GroupImportForm.ResultDeleted', 'Deleted %d groups',
+ array('count' => $result->DeletedCount())
);
$msg = ($msgArr) ? implode(',', $msgArr) : _t('MemberImportForm.ResultNone', 'No changes');
@@ -1299,12 +1299,12 @@ function providePermissions() {
$title = _t("{$class}.MENUTITLE", LeftAndMain::menu_title_for_class($class));
$perms["CMS_ACCESS_" . $class] = array(
- 'name' => sprintf(_t(
+ 'name' => _t(
'CMSMain.ACCESS',
- "Access to '%s' section",
-
- "Item in permission selection identifying the admin section. Example: Access to 'Files & Images'"
- ), $title, null),
+ "Access to '{title}' section",
+ "Item in permission selection identifying the admin section. Example: Access to 'Files & Images'",
+ array('title' => $title)
+ ),
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
);
}
@@ -75,17 +75,17 @@ function doImport($data, $form) {
// result message
$msgArr = array();
- if($result->CreatedCount()) $msgArr[] = sprintf(
- _t('MemberImportForm.ResultCreated', 'Created %d members'),
- $result->CreatedCount()
+ if($result->CreatedCount()) $msgArr[] = _t(
+ 'MemberImportForm.ResultCreated', 'Created {count} members',
+ array('count' => $result->CreatedCount())
);
- if($result->UpdatedCount()) $msgArr[] = sprintf(
- _t('MemberImportForm.ResultUpdated', 'Updated %d members'),
- $result->UpdatedCount()
+ if($result->UpdatedCount()) $msgArr[] = _t(
+ 'MemberImportForm.ResultUpdated', 'Updated {count} members',
+ array('count' => $result->UpdatedCount())
);
- if($result->DeletedCount()) $msgArr[] = sprintf(
- _t('MemberImportForm.ResultDeleted', 'Deleted %d members'),
- $result->DeletedCount()
+ if($result->DeletedCount()) $msgArr[] = _t(
+ 'MemberImportForm.ResultDeleted', 'Deleted %d members',
+ array('count' => $result->DeletedCount())
);
$msg = ($msgArr) ? implode(',', $msgArr) : _t('MemberImportForm.ResultNone', 'No changes');
@@ -376,17 +376,17 @@ function import($data, $form, $request) {
$results = $loader->load($_FILES['_CsvFile']['tmp_name']);
$message = '';
- if($results->CreatedCount()) $message .= sprintf(
- _t('ModelAdmin.IMPORTEDRECORDS', "Imported %s records."),
- $results->CreatedCount()
+ if($results->CreatedCount()) $message .= _t(
+ 'ModelAdmin.IMPORTEDRECORDS', "Imported {count} records.",
+ array('count' => $results->CreatedCount())
);
- if($results->UpdatedCount()) $message .= sprintf(
- _t('ModelAdmin.UPDATEDRECORDS', "Updated %s records."),
- $results->UpdatedCount()
+ if($results->UpdatedCount()) $message .= _t(
+ 'ModelAdmin.UPDATEDRECORDS', "Updated {count} records.",
+ array('count' => $results->UpdatedCount())
);
- if($results->DeletedCount()) $message .= sprintf(
- _t('ModelAdmin.DELETEDRECORDS', "Deleted %s records."),
- $results->DeletedCount()
+ if($results->DeletedCount()) $message .= _t(
+ 'ModelAdmin.DELETEDRECORDS', "Deleted {count} records.",
+ array('count' => $results->DeletedCount())
);
if(!$results->CreatedCount() && !$results->UpdatedCount()) $message .= _t('ModelAdmin.NOIMPORT', "Nothing to import");
@@ -219,7 +219,7 @@ function providePermissions() {
$title = _t("SecurityAdmin.MENUTITLE", LeftAndMain::menu_title_for_class($this->class));
return array(
"CMS_ACCESS_SecurityAdmin" => array(
- 'name' => sprintf(_t('CMSMain.ACCESS', "Access to '%s' section"), $title),
+ 'name' => _t('CMSMain.ACCESS', "Access to '{title}' section", array('title' => $title)),
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access'),
'help' => _t(
'SecurityAdmin.ACCESS_HELP',
View
@@ -496,28 +496,22 @@ public function validate() {
if(!$this->isValidSize()) {
$ext = (isset($pathInfo['extension'])) ? $pathInfo['extension'] : '';
$arg = File::format_size($this->getAllowedMaxFileSize($ext));
- $this->errors[] = sprintf(
- _t(
- 'File.TOOLARGE',
- 'Filesize is too large, maximum %s allowed.',
-
- 'Argument 1: Filesize (e.g. 1MB)'
- ),
- $arg
+ $this->errors[] = _t(
+ 'File.TOOLARGE',
+ 'Filesize is too large, maximum {size} allowed.',
+ 'Argument 1: Filesize (e.g. 1MB)',
+ array('size' => $arg)
);
return false;
}
// extension validation
if(!$this->isValidExtension()) {
- $this->errors[] = sprintf(
- _t(
- 'File.INVALIDEXTENSION',
- 'Extension is not allowed (valid: %s)',
-
- 'Argument 1: Comma-separated list of valid extensions'
- ),
- wordwrap(implode(', ', $this->allowedExtensions))
+ $this->errors[] = _t(
+ 'File.INVALIDEXTENSION',
+ 'Extension is not allowed (valid: {extensions})',
+ 'Argument 1: Comma-separated list of valid extensions',
+ array('extensions' => wordwrap(implode(', ', $this->allowedExtensions)))
);
return false;
}
@@ -485,12 +485,11 @@ function saveComplexTableField($data, $form, $params) {
$editLink = Controller::join_links($this->Link(), 'item/' . $childData->ID . '/edit');
- $message = sprintf(
- _t('ComplexTableField.SUCCESSADD', 'Added %s %s %s'),
- $childData->singular_name(),
- '<a href="' . $editLink . '">' . $childData->Title . '</a>',
- $closeLink
+ $message = _t(
+ 'ComplexTableField.SUCCESSADD2', 'Added {name}',
+ array('name' => $childData->singular_name())
);
+ $message .= '<a href="' . $editLink . '">' . $childData->Title . '</a>' . $closeLink;
$form->sessionMessage($message, 'good');
@@ -247,13 +247,25 @@ function validate($validator) {
if(($this->minLength || $this->maxLength)) {
if($this->minLength && $this->maxLength) {
$limit = "{{$this->minLength},{$this->maxLength}}";
- $errorMsg = sprintf(_t('ConfirmedPasswordField.BETWEEN', 'Passwords must be %s to %s characters long.'), $this->minLength, $this->maxLength);
+ $errorMsg = _t(
+ 'ConfirmedPasswordField.BETWEEN',
+ 'Passwords must be {min} to {max} characters long.',
+ array('min' => $this->minLength, 'max' => $this->maxLength)
+ );
} elseif($this->minLength) {
$limit = "{{$this->minLength}}.*";
- $errorMsg = sprintf(_t('ConfirmedPasswordField.ATLEAST', 'Passwords must be at least %s characters long.'), $this->minLength);
+ $errorMsg = _t(
+ 'ConfirmedPasswordField.ATLEAST',
+ 'Passwords must be at least {min} characters long.',
+ array('min' => $this->minLength)
+ );
} elseif($this->maxLength) {
$limit = "{0,{$this->maxLength}}";
- $errorMsg = sprintf(_t('ConfirmedPasswordField.MAXIMUM', 'Passwords must be at most %s characters long.'), $this->maxLength);
+ $errorMsg = _t(
+ 'ConfirmedPasswordField.MAXIMUM',
+ 'Passwords must be at most {max} characters long.',
+ array('max' => $this->maxLength)
+ );
}
$limitRegex = '/^.' . $limit . '$/';
if(!empty($value) && !preg_match($limitRegex,$value)) {
@@ -51,9 +51,10 @@ function validate($validator){
}
$validator->validationError(
$this->name,
- sprintf(
- _t('Form.VALIDATIONCREDITNUMBER', "Please ensure you have entered the %s credit card number correctly."),
- $number
+ _t(
+ 'Form.VALIDATIONCREDITNUMBER',
+ "Please ensure you have entered the {number} credit card number correctly.",
+ array('number' => $number)
),
"validation",
false
View
@@ -310,9 +310,9 @@ function validate($validator) {
if(!$valid) {
$validator->validationError(
$this->name,
- sprintf(
- _t('DateField.VALIDDATEFORMAT2', "Please enter a valid date format (%s)."),
- $this->getConfig('dateformat')
+ _t(
+ 'DateField.VALIDDATEFORMAT2', "Please enter a valid date format ({format}).",
+ array('format' => $this->getConfig('dateformat'))
),
"validation",
false
@@ -331,9 +331,9 @@ function validate($validator) {
if(!$this->valueObj->isLater($minDate) && !$this->valueObj->equals($minDate)) {
$validator->validationError(
$this->name,
- sprintf(
- _t('DateField.VALIDDATEMINDATE', "Your date has to be newer or matching the minimum allowed date (%s)"),
- $minDate->toString($this->getConfig('dateformat'))
+ _t(
+ 'DateField.VALIDDATEMINDATE', "Your date has to be newer or matching the minimum allowed date ({date})",
+ array('date' => $minDate->toString($this->getConfig('dateformat')))
),
"validation",
false
@@ -351,9 +351,9 @@ function validate($validator) {
if(!$this->valueObj->isEarlier($maxDate) && !$this->valueObj->equals($maxDate)) {
$validator->validationError(
$this->name,
- sprintf(
- _t('DateField.VALIDDATEMAXDATE', "Your date has to be older or matching the maximum allowed date (%s)"),
- $maxDate->toString($this->getConfig('dateformat'))
+ _t(
+ 'DateField.VALIDDATEMAXDATE', "Your date has to be older or matching the maximum allowed date ({date})",
+ array('date' => $maxDate->toString($this->getConfig('dateformat')))
),
"validation",
false
@@ -92,9 +92,11 @@ public function Field($properties = array()) {
)
);
} else {
- return sprintf(_t (
- 'FileIFrameField.ATTACHONCESAVED', '%ss can be attached once you have saved the record for the first time.'
- ), $this->FileTypeName());
+ return _t(
+ 'FileIFrameField.ATTACHONCESAVED',
+ '{type}s can be attached once you have saved the record for the first time.',
+ array('type' => $this->FileTypeName())
+ );
}
}
@@ -130,9 +132,9 @@ public function EditFileForm() {
$selectFile = _t('FileIFrameField.FROMFILESTORE', 'From the File Store');
if($this->AttachedFile() && $this->AttachedFile()->ID) {
- $title = sprintf(_t('FileIFrameField.REPLACE', 'Replace %s'), $this->FileTypeName());
+ $title = _t('FileIFrameField.REPLACE', 'Replace {type}', array('type' => $this->FileTypeName()));
} else {
- $title = sprintf(_t('FileIFrameField.ATTACH', 'Attach %s'), $this->FileTypeName());
+ $title = _t('FileIFrameField.ATTACH', 'Attach {type}', array('type' => $this->FileTypeName()));
}
$fileSources = array();
@@ -235,7 +237,7 @@ public function DeleteFileForm() {
),
new FieldList (
$deleteButton = new FormAction (
- 'delete', sprintf(_t('FileIFrameField.DELETE', 'Delete %s'), $this->FileTypeName())
+ 'delete', _t('FileIFrameField.DELETE', 'Delete {type}', array('type' => $this->FileTypeName()))
)
)
);
@@ -16,9 +16,9 @@ function validate($validator){
if($this->value && !is_numeric(trim($this->value))){
$validator->validationError(
$this->name,
- sprintf(
- _t('NumericField.VALIDATION', "'%s' is not a number, only numbers can be accepted for this field"),
- $this->value
+ _t(
+ 'NumericField.VALIDATION', "'{value}' is not a number, only numbers can be accepted for this field",
+ array('value' => $this->value)
),
"validation"
);
View
@@ -143,9 +143,9 @@ function validate($validator) {
if(!Zend_Date::isDate($this->value, $this->getConfig('timeformat'), $this->locale)) {
$validator->validationError(
$this->name,
- sprintf(
- _t('TimeField.VALIDATEFORMAT', "Please enter a valid time format (%s)"),
- $this->getConfig('timeformat')
+ _t(
+ 'TimeField.VALIDATEFORMAT', "Please enter a valid time format ({format})",
+ array('format' => $this->getConfig('timeformat'))
),
"validation",
false
View
@@ -348,23 +348,26 @@ public function Field($properties = array()) {
if (count($this->getValidator()->getAllowedExtensions())) {
$allowedExtensions = $this->getValidator()->getAllowedExtensions();
$config['acceptFileTypes'] = '(\.|\/)(' . implode('|', $allowedExtensions) . ')$';
- $config['errorMessages']['acceptFileTypes'] = sprintf(_t(
+ $config['errorMessages']['acceptFileTypes'] = _t(
'File.INVALIDEXTENSION',
- 'Extension is not allowed (valid: %s)'
- ), wordwrap(implode(', ', $allowedExtensions)));
+ 'Extension is not allowed (valid: {extensions})',
+ array('extensions' => wordwrap(implode(', ', $allowedExtensions)))
+ );
}
if ($this->getValidator()->getAllowedMaxFileSize()) {
$config['maxFileSize'] = $this->getValidator()->getAllowedMaxFileSize();
- $config['errorMessages']['maxFileSize'] = sprintf(_t(
+ $config['errorMessages']['maxFileSize'] = _t(
'File.TOOLARGE',
- 'Filesize is too large, maximum %s allowed.'
- ), File::format_size($config['maxFileSize']));
+ 'Filesize is too large, maximum {size} allowed.',
+ array('size' => File::format_size($config['maxFileSize']))
+ );
}
if ($config['maxNumberOfFiles'] > 1) {
- $config['errorMessages']['maxNumberOfFiles'] = sprintf(_t(
+ $config['errorMessages']['maxNumberOfFiles'] = _t(
'UploadField.MAXNUMBEROFFILES',
- 'Max number of %s file(s) exceeded.'
- ), $config['maxNumberOfFiles']);
+ 'Max number of {count} file(s) exceeded.',
+ array('count' => $config['maxNumberOfFiles'])
+ );
}
$configOverwrite = array();
if (is_numeric($config['maxNumberOfFiles']) && $this->getItems()->count()) {
@@ -459,10 +462,11 @@ public function upload(SS_HTTPRequest $request) {
// Report the constraint violation.
if ($tooManyFiles) {
if(!$this->getConfig('allowedMaxFileNumber')) $this->setConfig('allowedMaxFileNumber', 1);
- $return['error'] = sprintf(_t(
+ $return['error'] = _t(
'UploadField.MAXNUMBEROFFILES',
- 'Max number of %s file(s) exceeded.'
- ), $this->getConfig('allowedMaxFileNumber'));
+ 'Max number of {count} file(s) exceeded.',
+ array('count' => $this->getConfig('allowedMaxFileNumber'))
+ );
}
}
@@ -251,15 +251,15 @@ public function getPlaceholderText($dataClass) {
if($label) $labels[] = $label;
}
if($labels) {
- return sprintf(
- _t('GridField.PlaceHolderWithLabels', 'Find %s by %s', 'Find <object type> by <field names>'),
- singleton($dataClass)->plural_name(),
- implode(', ', $labels)
+ return _t(
+ 'GridField.PlaceHolderWithLabels',
+ 'Find {type} by {name}',
+ array('type' => singleton($dataClass)->plural_name(), 'name' => implode(', ', $labels))
);
} else {
- return sprintf(
- _t('GridField.PlaceHolder', 'Find %s', 'Find <object type>'),
- singleton($dataClass)->plural_name()
+ return _t(
+ 'GridField.PlaceHolder', 'Find {type}',
+ array('type' => singleton($dataClass)->plural_name())
);
}
}
Oops, something went wrong.

0 comments on commit 7b18d9d

Please sign in to comment.