Hints - show the original field content

Hints - show the original field content

When you translate a Page, most fields in the translated page are accompanied by 'hints', showing the original text on the 'master' page, to help keeping translations consistent. Unfortunately they are only available for fields that belong to the original Translatable object - in this case the SiteTree class.

So fields that are defined within subclasses, like Page, don't get the handy hints. But this can be remedied in your getCMSField() method, using the Translatable_Transformation class. It's a somewhat complex procedure where you first add the field as usual, and then replace it with something else. Suppose you defined this in your Page class:

public static $db = array(
    'ImportantText' => 'Varchar'

Now in your Page's getCMSFields(method you do (this is more ore less copied from the SilverStripe documentation):

// first create the textfield as usual
  $myField = new TextField('ImportantText', 'Enter important text')

// retrieve the 'master' Page from the default locale (if there is one)
$translation = $this->getTranslation(Translatable::default_locale());

// if the page exists check we're not already on the default locale 
// (question: should we not do this first?)
if($translation && $this->Locale != Translatable::default_locale()) {

	// create a 'Translatable_Transformation' object
	$transformation = new Translatable_Transformation($translation);

	// then replace the field by its transformFormField

Fix: replace the hints label (a hack)

It's maybe just me, but I'd like to change the way the original field gets the label 'Original Enter important text', where I'd just as soon would have them all labeled something like 'Original entry' - and have it translated depending on the user profile language! This can be patched (=hacked :-( ) in the Translatable class:

/sapphire/core/model/Translatable.php - line 1576:

// replace this
// $nonEditableField->setTitle('Original '.$originalField->Title());

// by this:
$nonEditableField->setTitle(_t('Translatable.ORIGINALENTRY', 'Original entry'));

Don't forget to add a new entry in the language files, so you have tis translation available for other profile languages.

Note: Extending the Translatable_Transformation class isn't really an option since it wouldn't affect what happens within the SiteTree class...

@TODO: I've no idea what would happen if I used this with the ComplexTableField - crash probably - will try later... 


Het versturen van reacties is uitgeschakeld.

RSS feed voor reacties op deze pagina