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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[SOLVED] Custom Form and site Multilanguage

Go to End

5 Posts   1776 Views


Forum Moderator, 435 Posts

25 February 2011 at 1:53am


I've a multilanguage site and I've created an input form with Form class in a Page class.

How translate field label?

Thank you


Community Member, 88 Posts

26 February 2011 at 2:36am

Edited: 26/02/2011 2:36am

Translating fields can be done with the _t function, e.g.

public function MyForm(){
   $fields = new FieldSet(
   new TextField('Name', _t('MyformPage.FIRST_LAST_NAME', 'Name'), '', 200),
   return new Form(....);


Forum Moderator, 435 Posts

26 February 2011 at 4:39am

How Do I use director::redirect in a multilanguage site?

That is from that form I have to redirect to a page in the site that is page-it or page-en...


Forum Moderator, 435 Posts

28 February 2011 at 6:53am

In my page controller where there is form, I write:

public function init(){

if($this->dataRecord->hasExtension('Translatable')) {

and for labels, I use _t('DisponibilitaPage.PRIVACY','Accetto Regolamento Privacy') in my Form costructor.

I my include template , I use for label <% _t('ROOM','Camera') %>

Language files was saved into lang folder under mysite. So, for this template, I use $lang['it_IT']['']['ROOM'] = 'Camera' and for class, I use $lang['it_IT']['DisponibilitaPage']['PRIVACY'] = 'Accetto Regolamento Privacy';



Community Member, 14 Posts

1 March 2011 at 1:16am

Edited: 01/03/2011 1:29am

Thank you, that's brilliant. Solved my template translation issues too!

I now have Italian and English text dropping into my custom form.

I added the above

if($this->dataRecord->hasExtension('Translatable')) { 

to mysite/page.php

And then in mysite/lang folder I have:


global $lang;
$lang['en_GB']['']['SIDEBARTITLE'] = 'English Title';



global $lang;

if(array_key_exists('it_IT', $lang) && is_array($lang['it_IT'])) {
	$lang['it_IT'] = array_merge($lang['en_GB'], $lang['it_IT']);
} else {
	$lang['it_IT'] = $lang['en_GB'];

$lang['it_IT']['']['SIDEBARTITLE'] = 'Italian Title';

then in themes/mytheme/templates/Includes/ I have:

<h3><% _t('SIDEBARTITLE','My English Title') %></h3>

This needs better documentation from Silverstripe itself. That little dataRecord>hasExtension bit in the Page Controller is totally KEY to it all working.

Yet it's never mentioned anywhere! (I'm looking at you Silverstripe Documentation:

Update: now I know what I'm looking for I've found it on this page [Which I had read several times] ( but says:

Unser the heading: Setting the i18n locale
You can set the i18n locale value which is used to format dates, currencies and other regionally different values to the same as your current page locale.

That doesn't say to me include this code to get your lang/<locale>.php files working. Thanks to the wonderful users of the SS Forum these bits of code are sorted out.

It's so difficult from a new user point of view.

When I've finished the project I'm on, I might write my own tutorial about languages, filtering page data objects and custom side bar forms.

All I don't know how to do now is make my Custom Form a "sticky" form. So if you select to filter by "Price Range 123" the drop down remembers that selection when the search is displayed instead of jumping back to the top item "Any". I guess I'll just be happy it's all working and get on with creating the rest of the site now.