Skip to content

Commit

Permalink
Removed direct sprintf() usage from _t() calls
Browse files Browse the repository at this point in the history
Parameterized strings are easier to understand,
and more fail-proof, don't fatal out when not enough sprintf() args
  • Loading branch information
chillu committed Dec 21, 2012
1 parent c054ab4 commit 661a4a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
11 changes: 9 additions & 2 deletions forms/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ public function php($data) {
}

if($formField && $error) {
$errorMessage = sprintf(_t('Form.FIELDISREQUIRED', '%s is required'),
strip_tags('"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"'));
$errorMessage = _t(
'Form.FIELDISREQUIRED',
'{name} is required',
array(
'name' => strip_tags(
'"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"'
)
)
);

if($msg = $formField->getCustomValidationMessage()) {
$errorMessage = $msg;
Expand Down
14 changes: 10 additions & 4 deletions forms/gridfield/GridFieldDetailForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,16 @@ public function doSave($data, $form) {

// TODO Save this item into the given relationship

$message = sprintf(
_t('GridFieldDetailForm.Saved', 'Saved %s %s'),
$this->record->singular_name(),
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
$link = '<a href="' . $this->Link('edit') . '">"'
. htmlspecialchars($this->record->Title, ENT_QUOTES)
. '"</a>';
$message = _t(
'GridFieldDetailForm.Saved',
'Saved {name} {link}',
array(
'name' => $this->record->singular_name(),
'link' => $link
)
);

$form->sessionMessage($message, 'good');
Expand Down
8 changes: 5 additions & 3 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
en:
AssetAdmin:
ALLOWEDEXTS: 'Allowed extensions'
NEWFOLDER: NewFolder
AssetTableField:
CREATED: 'First uploaded'
Expand Down Expand Up @@ -198,7 +197,7 @@ en:
TEXT2: 'password reset link'
TEXT3: for
Form:
FIELDISREQUIRED: '%s is required'
FIELDISREQUIRED: '{name} is required'
SubmitBtnLabel: Go
VALIDATIONCREDITNUMBER: 'Please ensure you have entered the {number} credit card number correctly'
VALIDATIONNOTUNIQUE: 'The value entered is not unique'
Expand Down Expand Up @@ -237,7 +236,9 @@ en:
DeletePermissionsFailure: 'No delete permissions'
Deleted: 'Deleted %s %s'
Save: Save
Saved: 'Saved %s %s'
Saved: 'Saved {name} {link}'
GridFieldEditButton.ss:
EDIT: Edit
GridFieldItemEditView.ss:
'Go back': 'Go back'
Group:
Expand Down Expand Up @@ -368,6 +369,7 @@ en:
NEWPASSWORD: 'New Password'
PASSWORD: Password
PLURALNAME: Members
PROFILESAVESUCCESS: 'Successfully saved.'
REMEMBERME: 'Remember me next time?'
SINGULARNAME: Member
SUBJECTPASSWORDCHANGED: 'Your password has been changed'
Expand Down

0 comments on commit 661a4a2

Please sign in to comment.