Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Allowing multiple language values for Textfield in CMS

Go to End

5 Posts   1802 Views


Community Member, 14 Posts

23 October 2010 at 10:32am


I feel like I must be missing something here and am not sure what. I'm running Silverstripe 2.4.2 and have configured Translatable and i18n as follows in my _config.php file.

/* ...

Object::add_extension('SiteTree', 'Translatable');

global $allowed_locales;
$allowed_locales = array(
      'fr_CA' => array('French (Canada)', 'fran&ccedil;ais'),
      'en_CA' => array('English (Canada)', 'English'),
i18n::$common_locales = $allowed_locales; 

I have been successful in creating pages in both english and french and the standard CMS fields (Page name, Navigation label, Content) all allow me to set different content in either of those languages.

However, I have added a CMS field as follows:

class LandingPage extends Page {
	public static $db = array(
			'ViewProjectLabel' => 'Text'

/* ... */

	function getCMSFields() {
		$fields = parent::getCMSFields();
		$viewprojectlabel = new TextField('ViewProjectLabel', 'View Project Label/Voir le projet');
		$fields->addFieldToTab('Root.Content.Settings', $viewprojectlabel);
		return $fields;

/* ... */

This field does not show up as the others do. Regardless which version of the page I'm editing (english or french) the field is always the same. The others show up as the familiar pairs of editable Content and greyed out Original Content.

Do I have to do anything else when I set up this field to indicate that I would like it to set different values for it in each language?

Please let me know if you need more info from me.



Community Member, 14 Posts

23 October 2010 at 1:30pm

Argh - I feel silly. Figured out where I was messing up. In _config.php I enabled Translatable for SiteTree and for some reason assumed that this extension would be inhereted by data objects declared in it's child classes SiteTree->Page->LandingPage.

I have since edited my _config.php to include all of the classes that require Translatable fields:

Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable');
Object::add_extension('LandingPage', 'Translatable');
Object::add_extension('CategorySlidePage', 'Translatable');
Object::add_extension('ProjectSlidePage', 'Translatable');

BUT I'm still left with the challenge for displaying the previous translation in a Original Content block. If I figure that out I will update the thread. Feel free to beat me to the punch though!


Community Member, 14 Posts

23 October 2010 at 1:45pm

Well now this is just getting embarassing... here is the code snippet for displaying a pair of fields showing Original Content and the translation Content:

		// If a translation exists, exchange them with 
		// original/translation field pairs
		$translation = $this->getTranslation(Translatable::default_locale());
		if($translation && $this->Locale != Translatable::default_locale()) {
			$transformation = new Translatable_Transformation($translation);

This snippet is directly from the SilverStripe docs:

Hope this can be of some help to others.


Community Member, 110 Posts

26 September 2011 at 8:50am

Hello, i've found that snippit also...It does place the extra field but did you figure out how to call that field in a template so it 'switches' according to the chosen locale?


Forum Moderator, 1899 Posts

29 September 2011 at 5:44am

I've recently done translation for a site and if you have Translateable added as an extension for the dataobject then you will get the translated version in the template - just the same as pages.