From 38f1236b1f830488d14d6312e78a3aab3cb6e027 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 1 May 2012 21:43:43 +0200 Subject: [PATCH] MINOR Switching _t() calls from sprintf() to using injection parameters (#7170) --- code/controllers/AssetAdmin.php | 8 ++- code/controllers/CMSMain.php | 62 +++++++++---------- code/controllers/CMSPageHistoryController.php | 17 +++-- code/controllers/ReportAdmin.php | 2 +- code/model/ErrorPage.php | 10 ++- code/model/SiteTree.php | 31 ++++------ code/model/VirtualPage.php | 12 ++-- code/reports/SideReport.php | 7 ++- lang/en.yml | 40 ++++++------ 9 files changed, 94 insertions(+), 95 deletions(-) diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 02a2a2e2..84a8d5aa 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -492,7 +492,11 @@ JS } } - $message = sprintf(_t('AssetAdmin.THUMBSDELETED', '%s unused thumbnails have been deleted'), $count); + $message = _t( + 'AssetAdmin.THUMBSDELETED', + '{count} unused thumbnails have been deleted', + array('count' => $count) + ); $this->response->addHeader('X-Status', $message); return; } @@ -594,7 +598,7 @@ JS $title = _t("AssetAdmin.MENUTITLE", LeftAndMain::menu_title_for_class($this->class)); return array( "CMS_ACCESS_AssetAdmin" => 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') ) ); diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 3c5ac1b7..5c5f5f7f 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -790,13 +790,11 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $this->response->addHeader( 'X-Status', - sprintf( - _t( - 'LeftAndMain.STATUSPUBLISHEDSUCCESS', - "Published '%s' successfully", - 'Status message after publishing a page, showing the page title' - ), - $record->Title + _t( + 'LeftAndMain.STATUSPUBLISHEDSUCCESS', + "Published '{title}' successfully", + 'Status message after publishing a page, showing the page title', + array('title' => $record->Title) ) ); } else { @@ -880,16 +878,16 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr if(isset($descendantsRemoved)) { $descRemoved = " and $descendantsRemoved descendants"; - $descRemoved = sprintf(' '._t('CMSMain.DESCREMOVED', 'and %s descendants'), $descendantsRemoved); + $descRemoved = ' ' . _t('CMSMain.DESCREMOVED', 'and {count} descendants', array('count' => $descendantsRemoved)); } else { $descRemoved = ''; } $form->sessionMessage( - sprintf( - _t('CMSMain.REMOVED', 'Deleted \'%s\'%s from live site'), - $recordTitle, - $descRemoved + _t( + 'CMSMain.REMOVED', + 'Deleted \'{title}\'{additionalinfo} from live site', + array('title' => $recordTitle, 'additionalinfo' => $descRemoved) ), 'good' ); @@ -936,9 +934,11 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $this->response->addHeader( 'X-Status', - sprintf( - _t('CMSMain.RESTORED',"Restored '%s' successfully",'Param %s is a title'), - $record->Title + _t( + 'CMSMain.RESTORED', + "Restored '{title}' successfully", + 'Param %s is a title', + array('title' => $record->Title) ) ); @@ -963,10 +963,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $record->delete(); $form->sessionMessage( - sprintf( - _t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"), - $record->Title - ), + _t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '{title}' from the draft site", array('title' => $record->Title)), 'good' ); @@ -991,7 +988,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $this->response->addHeader( 'X-Status', - sprintf(_t('CMSMain.REMOVEDPAGE',"Removed '%s' from the published site"),$record->Title) + _t('CMSMain.REMOVEDPAGE',"Removed '{title}' from the published site", array('title' => $record->Title)) ); return $this->getResponseNegotiator()->respond($this->request); @@ -1026,16 +1023,16 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr if($version) { $record->doRollbackTo($version); - $message = sprintf( - _t('CMSMain.ROLLEDBACKVERSION',"Rolled back to version #%d. New version number is #%d"), - $data['Version'], - $record->Version + $message = _t( + 'CMSMain.ROLLEDBACKVERSION', + "Rolled back to version #%d. New version number is #%d", + array('version' => $data['Version'], 'versionnew' => $record->Version) ); } else { $record->doRollbackTo('Live'); - $message = sprintf( - _t('CMSMain.ROLLEDBACKPUB',"Rolled back to published version. New version number is #%d"), - $record->Version + $message = _t( + 'CMSMain.ROLLEDBACKPUB',"Rolled back to published version. New version number is #{version}", + array('version' => $record->Version) ); } @@ -1150,7 +1147,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr break; } } - $response .= sprintf(_t('CMSMain.PUBPAGES',"Done: Published %d pages"), $count); + $response .= _t('CMSMain.PUBPAGES',"Done: Published {count} pages", array('count' => $count)); } else { $token = SecurityToken::inst(); @@ -1188,9 +1185,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $this->response->addHeader( 'X-Status', - sprintf( - _t('CMSMain.RESTORED',"Restored '%s' successfully",'Param %s is a title'), - $restoredPage->TreeTitle + _t( + 'CMSMain.RESTORED', + "Restored '{title}' successfully", + array('title' => $restoredPage->TreeTitle) ) ); @@ -1268,7 +1266,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $title = _t("CMSPagesController.MENUTITLE", LeftAndMain::menu_title_for_class('CMSPagesController')); return array( "CMS_ACCESS_CMSMain" => 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( 'CMSMain.ACCESS_HELP', diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php index 8ab026c2..1673bb80 100644 --- a/code/controllers/CMSPageHistoryController.php +++ b/code/controllers/CMSPageHistoryController.php @@ -99,17 +99,22 @@ class CMSPageHistoryController extends CMSMain { $view = _t('CMSPageHistoryController.VIEW',"view"); - $message = sprintf( - _t('CMSPageHistoryController.COMPARINGVERSION',"Comparing versions %s and %s."), - sprintf('%s (%s)', $versionID, Controller::join_links($link, $versionID), $view), - sprintf('%s (%s)', $compareID, Controller::join_links($link, $compareID), $view) + $message = _t( + 'CMSPageHistoryController.COMPARINGVERSION', + "Comparing versions {version1} and {version2}.", + array( + 'version1' => sprintf('%s (%s)', $versionID, Controller::join_links($link, $versionID), $view), + 'version2' => sprintf('%s (%s)', $compareID, Controller::join_links($link, $compareID), $view) + ) ); $revert->setReadonly(true); } else { - $message = sprintf( - _t('CMSPageHistoryController.VIEWINGVERSION',"Currently viewing version %s."), $versionID + $message = _t( + 'CMSPageHistoryController.VIEWINGVERSION', + "Currently viewing version {version}.", + array('version' => $versionID) ); } diff --git a/code/controllers/ReportAdmin.php b/code/controllers/ReportAdmin.php index 10dd5c43..06f48310 100644 --- a/code/controllers/ReportAdmin.php +++ b/code/controllers/ReportAdmin.php @@ -140,7 +140,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider { $title = _t("ReportAdmin.MENUTITLE", LeftAndMain::menu_title_for_class($this->class)); return array( "CMS_ACCESS_ReportAdmin" => 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') ) ); diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php index bb259c83..7962fe33 100644 --- a/code/model/ErrorPage.php +++ b/code/model/ErrorPage.php @@ -204,12 +204,10 @@ class ErrorPage extends Page { fwrite($fh, $errorContent); fclose($fh); } else { - $fileErrorText = sprintf( - _t( - "ErrorPage.ERRORFILEPROBLEM", - "Error opening file \"%s\" for writing. Please check file permissions." - ), - $errorFile + $fileErrorText = _t( + "ErrorPage.ERRORFILEPROBLEM", + "Error opening file \"{filename}\" for writing. Please check file permissions.", + array('filename' => $errorFile) ); $this->response->addHeader('X-Status', $fileErrorText); return $this->httpError(405); diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 2611d387..69b952c5 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -1495,14 +1495,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid if($subject->ID && !in_array($subject->ClassName, $allowed)) { $result->error( - sprintf( - _t( - 'SiteTree.PageTypeNotAllowed', - 'Page type "%s" not allowed as child of this parent page', - - 'First argument is a class name' - ), - $subject->i18n_singular_name() + _t( + 'SiteTree.PageTypeNotAllowed', + 'Page type "{type}" not allowed as child of this parent page', + array('type' => $subject->i18n_singular_name()) ), 'ALLOWED_CHILDREN' ); @@ -1512,14 +1508,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // "Can be root" validation if(!$this->stat('can_be_root') && !$this->ParentID) { $result->error( - sprintf( - _t( - 'SiteTree.PageTypNotAllowedOnRoot', - 'Page type "%s" is not allowed on the root level', - - 'First argument is a class name' - ), - $this->i18n_singular_name() + _t( + 'SiteTree.PageTypNotAllowedOnRoot', + 'Page type "{type}" is not allowed on the root level', + array('type' => $this->i18n_singular_name()) ), 'CAN_BE_ROOT' ); @@ -1781,9 +1773,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid . $parentList; } - $statusMessage[] = sprintf( - _t('SiteTree.APPEARSVIRTUALPAGES', "This content also appears on the virtual pages in the %s sections."), - $parentList + $statusMessage[] = _t( + 'SiteTree.APPEARSVIRTUALPAGES', + "This content also appears on the virtual pages in the {title} sections.", + array('title' => $parentList) ); } } diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index ae289729..9749fe10 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -301,14 +301,10 @@ class VirtualPage extends Page { $orig = $this->CopyContentFrom(); if(!$orig->stat('can_be_root') && !$this->ParentID) { $result->error( - sprintf( - _t( - 'VirtualPage.PageTypNotAllowedOnRoot', - 'Original page type "%s" is not allowed on the root level for this virtual page', - - 'First argument is a class name' - ), - $orig->i18n_singular_name() + _t( + 'VirtualPage.PageTypNotAllowedOnRoot', + 'Original page type "{type}" is not allowed on the root level for this virtual page', + array('type' => $orig->i18n_singular_name()) ), 'CAN_BE_ROOT_VIRTUAL' ); diff --git a/code/reports/SideReport.php b/code/reports/SideReport.php index c5c3b6aa..c08c231a 100644 --- a/code/reports/SideReport.php +++ b/code/reports/SideReport.php @@ -50,9 +50,10 @@ class SideReportView extends ViewableData { $result .= "\n"; } else { $result = "

" . - sprintf( - _t('SideReport.REPEMPTY','The %s report is empty.','%s is a report title'), - $this->report->title() + _t( + 'SideReport.REPEMPTY', + 'The {title} report is empty.', + array('title' => $this->report->title()) ) . "

"; } diff --git a/lang/en.yml b/lang/en.yml index 6323e0bd..9bcf6640 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -19,7 +19,7 @@ en: ListView: 'List View' NEWFOLDER: NewFolder SIZE: Size - THUMBSDELETED: '%s unused thumbnails have been deleted' + THUMBSDELETED: '{count} unused thumbnails have been deleted' TreeView: 'Tree View' Upload: Upload MENUTITLE: Files @@ -65,7 +65,7 @@ en: UNPUBLISHED_PAGES: 'Un-published %d pages' UNPUBLISH_PAGES: Un-publish CMSMain: - ACCESS: 'Access to ''%s'' section' + ACCESS: 'Access to ''{title}'' section' ACCESS_HELP: 'Allow viewing of the section containing page tree and content. View and edit permissions can be handled through page specific dropdowns, as well as the separate "Content permissions".' AddNew: 'Add new page' AddNewButton: 'Add new' @@ -74,7 +74,7 @@ en: Create: Create DELETE: 'Delete draft' DELETEFP: Delete - DESCREMOVED: 'and %s descendants' + DESCREMOVED: 'and {count} descendants' EMAIL: Email NEW: 'New ' PAGENOTEXISTS: 'This page doesn''t exist' @@ -84,14 +84,14 @@ en: PUBALLCONFIRM: 'Please publish every page in the site, copying content stage to live' PUBALLFUN: '"Publish All" functionality' PUBALLFUN2: "Pressing this button will do the equivalent of going to every page and pressing \"publish\". It's\n intended to be used after there have been massive edits of the content, such as when the site was\n first built." - PUBPAGES: 'Done: Published %d pages' - REMOVED: 'Deleted ''%s''%s from live site' - REMOVEDPAGE: 'Removed ''%s'' from the published site' - REMOVEDPAGEFROMDRAFT: 'Removed ''%s'' from the draft site' + PUBPAGES: 'Done: Published {count} pages' + REMOVED: 'Deleted ''{title}''{additionalinfo} from live site' + REMOVEDPAGE: 'Removed ''{title}'' from the published site' + REMOVEDPAGEFROMDRAFT: 'Removed ''{title}'' from the draft site' RESTORE: Restore - RESTORED: 'Restored ''%s'' successfully' + RESTORED: 'Restored ''{title}'' successfully' ROLLBACK: 'Roll back to this version' - ROLLEDBACKPUB: 'Rolled back to published version. New version number is #%d' + ROLLEDBACKPUB: 'Rolled back to published version. New version number is #{version}' ROLLEDBACKVERSION: 'Rolled back to version #%d. New version number is #%d' SAVE: Save SAVEDRAFT: 'Save Draft' @@ -109,12 +109,12 @@ en: CMSPageHistoryController: COMPAREMODE: 'Compare mode (select two)' COMPAREVERSIONS: 'Compare Versions' - COMPARINGVERSION: 'Comparing versions %s and %s.' + COMPARINGVERSION: 'Comparing versions {version1} and {version2}.' REVERTTOTHISVERSION: 'Revert to this version' SHOWUNPUBLISHED: 'Show unpublished versions' SHOWVERSION: 'Show Version' VIEW: view - VIEWINGVERSION: 'Currently viewing version %s.' + VIEWINGVERSION: 'Currently viewing version {version}.' MENUTITLE: History CMSPageHistoryController_versions.ss: AUTHOR: Author @@ -187,7 +187,7 @@ en: DEFAULTSERVERERRORPAGECONTENT: '

Sorry, there was a problem with handling your request.

' DEFAULTSERVERERRORPAGETITLE: 'Server error' DESCRIPTION: 'Custom content for different error cases (e.g. "Page not found")' - ERRORFILEPROBLEM: 'Error opening file "%s" for writing. Please check file permissions.' + ERRORFILEPROBLEM: 'Error opening file "{filename}" for writing. Please check file permissions.' Folder: AddFolderButton: 'Add folder' DELETEUNUSEDTHUMBNAILS: 'Delete unused thumbnails' @@ -198,7 +198,7 @@ en: DESCRIPTION: 'Generic content page' LeftAndMain: PreviewButton: Preview - STATUSPUBLISHEDSUCCESS: 'Published ''%s'' successfully' + STATUSPUBLISHEDSUCCESS: 'Published ''{title}'' successfully' SearchResults: 'Search Results' VersionUnknown: Unknown LegacyTableFieldsTestPage: @@ -246,7 +246,7 @@ en: LAST2WEEKS: 'Pages edited in the last 2 weeks' OtherGroupTitle: Other ParameterLiveCheckbox: 'Check live site' - REPEMPTY: 'The %s report is empty.' + REPEMPTY: 'The {title} report is empty.' SilverStripeNavigatorLink: ShareInstructions: 'To share a this to this page, copy and paste the link below.' ShareLink: 'Share link' @@ -271,9 +271,10 @@ en: ACCESSHEADER: 'Who can view this page?' ACCESSLOGGEDIN: 'Logged-in users' ACCESSONLYTHESE: 'Only these people (choose from list)' + ADDEDTODRAFTHELP: 'Page has not been published yet' ADDEDTODRAFTSHORT: Draft ALLOWCOMMENTS: 'Allow comments on this page?' - APPEARSVIRTUALPAGES: 'This content also appears on the virtual pages in the %s sections.' + APPEARSVIRTUALPAGES: 'This content also appears on the virtual pages in the {title} sections.' BUTTONCANCELDRAFT: 'Cancel draft changes' BUTTONCANCELDRAFTDESC: 'Delete your draft and revert to the currently published page' BUTTONSAVEPUBLISH: 'Save & Publish' @@ -289,6 +290,7 @@ en: DEFAULTCONTACTTITLE: 'Contact Us' DEFAULTHOMECONTENT: '

Welcome to SilverStripe! This is the default homepage. You can edit this page by opening the CMS. You can now access the developer documentation, or begin the tutorials.

' DEFAULTHOMETITLE: Home + DELETEDPAGEHELP: 'Page is no longer published' DELETEDPAGESHORT: Deleted DEPENDENT_NOTE: 'The following pages depend on this page. This includes virtual pages, redirector pages, and pages with content links.' DependtPageColumnLinkType: 'Link type' @@ -310,6 +312,7 @@ en: METAEXTRA: 'Custom Meta Tags' METAKEYWORDS: 'Meta Keywords' METATITLE: 'Meta Title' + MODIFIEDONDRAFTHELP: 'Page has unpublished changes' MODIFIEDONDRAFTSHORT: Modified PAGELOCATION: 'Page location' PAGETITLE: 'Page name' @@ -321,8 +324,9 @@ en: PERMISSION_GRANTACCESS_DESCRIPTION: 'Manage access rights for content' PERMISSION_GRANTACCESS_HELP: 'Allow setting of page-specific access restrictions in the "Pages" section.' PLURALNAME: 'Site Tres' - PageTypNotAllowedOnRoot: 'Page type "%s" is not allowed on the root level' - PageTypeNotAllowed: 'Page type "%s" not allowed as child of this parent page' + PageTypNotAllowedOnRoot: 'Page type "{type}" is not allowed on the root level' + PageTypeNotAllowed: 'Page type "{type}" not allowed as child of this parent page' + REMOVEDFROMDRAFTHELP: 'Page is published, but has been deleted from draft' REMOVEDFROMDRAFTSHORT: 'Removed from draft' REMOVE_INSTALL_WARNING: 'Warning: You should remove install.php from this SilverStripe install for security reasons.' REORGANISE_DESCRIPTION: 'Change site structure' @@ -378,7 +382,7 @@ en: EDITCONTENT: 'click here to edit the content' HEADER: 'This is a virtual page' PLURALNAME: 'Virtual Pags' - PageTypNotAllowedOnRoot: 'Original page type "%s" is not allowed on the root level for this virtual page' + PageTypNotAllowedOnRoot: 'Original page type "{type}" is not allowed on the root level for this virtual page' SINGULARNAME: 'Virtual Page' cms: FILESYSTEMSYNC: 'Sync files'