From cb96255e8072ec62867ac754d1540f5c98636f71 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 21 Dec 2012 11:18:18 +0100 Subject: [PATCH] Removed direct sprintf() usage from _t() calls Parameterized strings are easier to understand, and more fail-proof, don't fatal out when not enough sprintf() args --- code/controllers/CMSMain.php | 15 ++++++++++++--- lang/en.yml | 12 +++++------- tasks/SiteTreeMaintenanceTask.php | 12 ++++++++++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index c3477a90..27cc5ca2 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -927,15 +927,24 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr Versioned::reading_stage('Stage'); if(isset($descendantsRemoved)) { - $descRemoved = " and $descendantsRemoved descendants"; - $descRemoved = ' ' . _t('CMSMain.DESCREMOVED', 'and {count} descendants', array('count' => $descendantsRemoved)); + $descRemoved = ' ' . _t( + 'CMSMain.DESCREMOVED', + 'and {count} descendants', + array('count' => $descendantsRemoved) + ); } else { $descRemoved = ''; } $this->response->addHeader( 'X-Status', - rawurlencode(sprintf(_t('CMSMain.REMOVED', 'Deleted \'%s\'%s from live site'), $recordTitle, $descRemoved)) + rawurlencode( + _t( + 'CMSMain.REMOVED', + 'Deleted \'{title}\'{description} from live site', + array('title' => $recordTitle, 'description' => $descRemoved) + ) + ) ); // Even if the record has been deleted from stage and live, it can be viewed in "archive mode" diff --git a/lang/en.yml b/lang/en.yml index 7c539828..777402c9 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -1,6 +1,7 @@ en: AssetAdmin: ADDFILES: 'Add Files' + ALLOWEDEXTS: 'Allowed extensions' ActionAdd: 'Add folder' AppCategoryArchive: Archive AppCategoryAudio: Audio @@ -93,7 +94,7 @@ en: 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 {count} pages' PageAdded: 'Successfully created page' - REMOVED: 'Deleted ''%s''%s from live site' + REMOVED: 'Deleted ''{title}''{description} from live site' REMOVEDPAGE: 'Removed ''{title}'' from the published site' REMOVEDPAGEFROMDRAFT: 'Removed ''%s'' from the draft site' RESTORE: Restore @@ -138,7 +139,6 @@ en: MENUTITLE: Pages TreeView: 'Tree View' CMSPagesController_ContentToolbar.ss: - ENABLEDRAGGING: 'Drag''n''drop' MULTISELECT: Multi-selection CMSPagesController_Tools.ss: FILTER: Filter @@ -173,7 +173,7 @@ en: PUBLISHEDSITE: 'Published Site' Password: Password PostInstallTutorialIntro: 'This website is a simplistic version of a SilverStripe 3 site. To extend this, please take a look at {link}.' - StartEditing: 'You can start editing your site\''s content by opening the CMS.' + StartEditing: 'You can start editing your content by opening the CMS.' UnableDeleteInstall: 'Unable to delete installation files. Please delete the files below manually' VIEWPAGEIN: 'View Page in:' ErrorPage: @@ -323,9 +323,9 @@ en: LINKCHANGENOTE: 'Changing this page''s link will also affect the links of all child pages.' MENUTITLE: 'Navigation label' METADESC: 'Meta Description' - METADESCHELP: 'Search engines use this content for displaying search results (although it will not influence their ranking).' METAEXTRA: 'Custom Meta Tags' - METAEXTRAHELP: 'HTML tags for additional meta information. For example <meta name="customName" content="your custom content here" />' + METAKEYWORDS: 'Meta Keywords' + METATITLE: 'Meta Title' MODIFIEDONDRAFTHELP: 'Page has unpublished changes' MODIFIEDONDRAFTSHORT: Modified MetadataToggle: Metadata @@ -387,8 +387,6 @@ en: VIEWLAST: 'View last' VIEWNEXT: 'View next' VIEWPREVIOUS: 'View previous' - TreeTools: - DisplayLabel: 'Display:' ViewArchivedEmail.ss: CANACCESS: 'You can access the archived site at this link:' HAVEASKED: 'You have asked to view the content of our site on' diff --git a/tasks/SiteTreeMaintenanceTask.php b/tasks/SiteTreeMaintenanceTask.php index 0c1f4f91..f0370c29 100644 --- a/tasks/SiteTreeMaintenanceTask.php +++ b/tasks/SiteTreeMaintenanceTask.php @@ -17,10 +17,18 @@ class SiteTreeMaintenanceTask extends Controller { $urlSegment = $page->URLSegment; $page->write(); if($urlSegment != $page->URLSegment) { - echo sprintf(_t('SiteTree.LINKSCHANGEDTO', " changed %s -> %s"), $urlSegment, $page->URLSegment); + echo _t( + 'SiteTree.LINKSCHANGEDTO', + " changed {url1} -> {url2}", + array('url1' => $urlSegment, 'url2' => $page->URLSegment) + ); } else { - echo sprintf(_t('SiteTree.LINKSALREADYUNIQUE', " %s is already unique"), $urlSegment); + echo _t( + 'SiteTree.LINKSALREADYUNIQUE', + " {url} is already unique", + array('url' => $urlSegment) + ); } die(); }