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

Multilingual Content - alternative to 'translatable'

Go to End

44 Posts   13923 Views


Community Member, 127 Posts

16 April 2009 at 1:03am


if you want the forms, such as shown on the checkout page, multilingual, then, as a first step, you need to enable i18n.

That alone is not enough though. In the trunk ecommerce module many (but not all) displayed strings are i18n enabled, however even if the translation exists, SS does not find it, and thus not display it (SS 2.3.1).

Fortunately that is not difficult to fix. Let's take for example the checkout form, personal details. That part of the form is defined in ecommerce/code/model/EcommerceRole.php, and is not i18n enabled yet. The textfields are defined with

new TextField('FirstName', 'First Name'),

which needs to get changed to

new TextField('FirstName', _t('Member.FIRSTNAME','First Name')),

here is the complete modified function:

	 * Return the member fields to be shown on order forms.
	 * For orders made by existing members, this will be called on that member.
	 * For new orders, this will be called on the singleton object.
	 * Modified by Kalileo 2009-04-15 
	 * to include " _t('Member.FIRSTNAME','First Name'),"
	 * instead of "new TextField('FirstName', 'First Name'),". 
	 * at the relevant fields in order to enable i18n automatic translations
	 * This will use the existing translation in "Member." and ""
	function getEcommerceFields() {
		$fields = new FieldSet(
			new HeaderField(_t('','Personal Information'), 3),
			new TextField('FirstName', _t('Member.FIRSTNAME','First Name')),
			new TextField('Surname',  _t('Member.SURNAME','Surname')),
			new TextField('HomePhone',  _t('','Phone')),
			new TextField('MobilePhone',  _t('','Mobile')),
			new EmailField('Email',  _t('','Email')),
			new TextField('Address',  _t('','Address')),
			new TextField('AddressLine2', ''),
			new TextField('City',  _t('','City')),
			new DropdownField('Country',  _t('','Country'), Geoip::getCountryDropDown(), self::findCountry())
		$this->owner->extend('augmentEcommerceFields', $fields);
		return new CompositeField($fields);

with that code a call to e.g. domain.tld/de/checkout/?flush=1 should now show the labels of these fields in German (assuming your cart is not empty).

I hope this helps you to find the required modifications in your code.


Community Member, 31 Posts

17 April 2009 at 5:51am

I am trying to use the recipe and
I've already changed the protected function to public function getField($field) { ... as suggested but
still getting a Fatal Error: Class 'MultiLingual' not found.

I am on 2.3.1

Any help is appreciated.


Community Member, 127 Posts

1 May 2009 at 6:02pm

To add to my post to posts above, this ticket explains why often it is (still) necessary to use the long form of the i18n function _t() as in _t('Member.FIRSTNAME','First Name') and not only the short form _t('FIRSTNAME','First Name')

The short form will apparently work also in nested templates not before 2.3.3. However you can always apply the fix Henk Poley describes in that ticket . Thanks Henk Poley!


Community Member, 46 Posts

1 May 2009 at 6:05pm

Cem - Have you created the Multilingual class as outlined in the wiki article, and run a db/build?


Community Member, 31 Posts

10 May 2009 at 11:06pm

Hi Apophenian:
I did create the Multilingual class and everything as the wiki and eventually gave up trying to implement this workaround.
My problem however is solved with the latest beta release 2.3.2 and translatable seems to be working again.
Thanks for your response anyways!


Community Member, 215 Posts

24 May 2009 at 10:03pm

Hey with help from simon_w I got the homepage working as expected in 2.3.2, I changed the code to:

class MultiLingual extends ModelAsController {	
	static $lang;	
	function init() {
		$baseUrl = Director::baseUrl();
		$requestUri = $_SERVER['REQUEST_URI'];
		$lang = substr($requestUri, strlen($baseUrl), 2);		
		self::$lang = $lang;
		//prevents default behaviour of redirecting to '/' for '/en/'
		if($this->URLParams['URLSegment'] == "" || $this->URLParams['URLSegment'] == 'home') {
			$urlparams = array('URLSegment' => 'home', 'Action' => ' ');
			if(self::$lang == 'mr'){
				$_POST['this_is_a_hack_to_stop_the_home_redirect'] = true;
	static function currentLang() {
		return self::$lang;

The if(self::$lang == 'mr') isn't totally required I don't think, but have a play and reply if this works for you.


Community Member, 73 Posts

23 June 2009 at 3:20am


Is there a way to display custom includes evaluating the current language?
I find this very difficult to do, and since i'm not a programmer, all that i've tried was messing up the layout or giving me errors...

All i need is to have a conditional that evaluates current language, to display a custom sidebar, wich now is an include from

If anyone can post here a way to evaluate the language inside the .ss files to include another, that would be great !

Thanks in advance,




Community Member, 215 Posts

23 June 2009 at 8:30am

Yup, this is how i do it. I include the following function in my Page class:

public function LangIsMaori() {
		$lang = MultiLingual::currentLang();
		if($lang == 'mr'){
		return true;

Which then allows me to use this anywhere in my templates:
<% if LangIsMaori %>
      <h2>Ngā mahi whai muri mai</h2>
<% else %>
      <h2>Upcoming Events</h2>
<% end_if %>