Translate 'new-page' in SiteTree

Translate the default name for a new page in the SiteTree

When you add a new page to the SiteTree, its (Menu)Title is created based on the PageType ClassName, preceded by whatever translation of the keyword 'new'. This results in titles like 'new MyContactPage' where you'd want 'new contact page' or 'nieuwe contactpagina' based on the users locale... The user will change it anyway, but still it doen't look nice. To remedy:

Language file

Make sure you provide a translation for every pagetype's singularname in your languagefiles (if you use i18nTextCollector, it will do it for you):

$lang['en_US']['MyContactPage']['SINGULAR_NAME'] = 'contact page';

Add the new name befor the page is first written

Next add the following code to your Page class (will work for alle extended pages as well): 

function onBeforeWrite(){
parent::onBeforeWrite();
if (empty($this->ID)) {
$this->Title = _t('CMSMain.NEW', 'new') . ' ' . $this->i18n_singular_name();
}
}

Comments

Het versturen van reacties is uitgeschakeld.

RSS feed voor reacties op deze pagina