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.

General Questions

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

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

How to translate fields labels


Go to End
Reply

9 Posts   2984 Views

Avatar
Tonyair

24 September 2010 at 7:41am Community Member, 81 Posts

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

24 September 2010 at 8:28am Community Member, 271 Posts

Add this to you DataObject:

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

      return $labels;
   }

Avatar
Tonyair

24 September 2010 at 8:52am (Last edited: 24 September 2010 8:54am), Community Member, 81 Posts

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

24 September 2010 at 9:10am Community Member, 81 Posts

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

24 September 2010 at 11:00am Community Member, 271 Posts

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

24 September 2010 at 6:47pm Community Member, 81 Posts

Great, thx =)

Avatar
batpurev

25 September 2010 at 6:33pm Community Member, 1 Post

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

25 September 2010 at 7:54pm Community Member, 81 Posts

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