Jump to:

23358 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » How to translate fields labels

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

Page: 1 2
Go to End
Author Topic: 2860 Views
  • Tonyair
    Avatar
    Community Member
    81 Posts

    How to translate fields labels Link to this post

    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)')

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: How to translate fields labels Link to this post

    Add this to you DataObject:

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

          return $labels;
       }

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: How to translate fields labels Link to this post

    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

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: How to translate fields labels Link to this post

    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

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: How to translate fields labels Link to this post

    Trunk is updated for translatable Heading Labels in TableField.

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

    Please let me know if this works for you..

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: How to translate fields labels Link to this post

    Great, thx =)

  • batpurev
    Avatar
    Community Member
    1 Post

    Re: How to translate fields labels Link to this 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.

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: How to translate fields labels Link to this post

    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";

    2860 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.