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

How to translate fields labels


Go to End


10 Posts   6023 Views

Avatar
Tonyair

Community Member, 81 Posts

24 September 2010 at 7:41am

I'd like to translate fields of custom data object

	static $db = array(
		'Title'			=> 'Varchar(100)'
	);

I tried: $lang['lang']['Product']['db_Title'] = 'Name'; and function fieldLabels () {$labels['Title'] = 'Name';}

But getting error in TableField class
line 135: $class = $this->fieldTypes[$fieldName];

'cos
$this->fieldList looks like array( 'Title' => 'Title');
but $this->fieldTypes became array ('Name' => 'Varchar(100)')

Avatar
Martijn

Community Member, 271 Posts

24 September 2010 at 8:28am

Add this to you DataObject:

function fieldLabels() {	
		$labels = parent::fieldLabels();
		
		$labels['Title']	= _t('SomeDataObject.Title', "SomeTranslatableTitle");		

		return $labels;
	}

Avatar
Tonyair

Community Member, 81 Posts

24 September 2010 at 8:52am

Edited: 24/09/2010 8:54am

Yes, I tried as I said before, but anyway I'm getting error from TableField class

I think that should be:

$this->fieldList = array( 'FIELDNAME' => 'FIELDLABEL');

and

$this->fieldTypes = array( 'FIELDNAME' => 'FIELDTYPE');

But I'm getting:

$this->fieldList = array( 'FIELDNAME' => 'FIELDNAME');
$this->fieldTypes = array( 'FIELDLABEL' => 'FIELDTYPE');

That's why when FieldTable class parses $this->fieldList array and trying to get $this->fieldTypes['FIELDNAME'] property it gets nothing, so I think it's core error somewhere but I can't find where.

Both mentioned methods of translation works perfectly anywhere but not with TableField

Avatar
Tonyair

Community Member, 81 Posts

24 September 2010 at 9:10am

Hmm .. I made an experiment

class WareAdmin extends ModelAdmin {
	public static $managed_models = array(
		'Product'
	);
 
	static $url_segment = 'warehouse';
	static $menu_title = 'Ware House Control';
	function getEditForm(){ 
		return $this->bindModelController('Product')->ResultsForm(array()); 
	}
}

Field translation works fine with ModelAdmin, but doesn't work in PanelModelAdmin

Avatar
Martijn

Community Member, 271 Posts

24 September 2010 at 11:00am

Trunk is updated for translatable Heading Labels in TableField.

http://svn.axyrmedia.nl/panelmodeladmin/trunk/

Please let me know if this works for you..

Avatar
Tonyair

Community Member, 81 Posts

24 September 2010 at 6:47pm

Great, thx =)

Avatar
batpurev

Community Member, 1 Post

25 September 2010 at 6:33pm

hey, does this SilverStripe have localization tool? for instance on trasifix.net? How translators will work? I did not find any clue on the website. someone plz give me a hint thanks.

Avatar
Tonyair

Community Member, 81 Posts

25 September 2010 at 7:54pm

Here's manual
http://doc.silverstripe.org/i18n

for field labels just add to mysite/lang/*lang*.php
$lang[*lang*][*Classname*]['db_*fieldname*] = "Field translation";

Go to Top