Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » i18n: Setting a proper name for a new tab

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1757 Views
  • dewoob
    Avatar
    Community Member
    10 Posts

    i18n: Setting a proper name for a new tab Link to this post

    Hi everyone,

    I made a new tab as shown in the tutorial:

    In Page::getCMSFields():

    $fields->addFieldToTab( 'Root.Content.Side', new HtmlEditorField( 'SideContent', 'Side Content' ) );

    The tab has no proper name, it's displayed simply as "Side". When I set the locale to German, it should say "Neben-Inhalte".

    I found a solution, but I wonder if there's a better one:

    In FieldSet.php, I changed the addFieldToTab method, so that it no longer returns "void", but returns $tab, the tab that has been found or created by protected method FieldSet::findOrMakeTab().

    Having the tab on hand, I can call $tab->setTitle( _t(...) ) :

    In Page::getCMSFields():

    $sideTab = $fields->addFieldToTab( 'Root.Content.Side', new TextareaField( 'FooterText', 'Footer Text', 3, 200 ) );
    $sideTab->setTitle(_t('SiteTree.TABSIDE', "Side contents"));

    Is there any better way to do this, without changing core functionality?

    Thank you!

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: i18n: Setting a proper name for a new tab Link to this post

    could you just pass the translated tab name to the add field to tab method before rather then after you create the tab, then you dont have to mess around with the core??

    Eg something like...

    $myTabTitle = _t('SiteTree.TABSIDE', "Side contents");

    $fields->addFieldToTab("Root.Content.". $myTabTitle ."", new TextField('Blah'));

  • dewoob
    Avatar
    Community Member
    10 Posts

    Re: i18n: Setting a proper name for a new tab Link to this post

    Hi willr!

    Of course, if it's that easy ... thank you! I'm new to silverstripe and I don't yet know the system exactly... This "Root.Content.Side" array key just looked like some "important" identifier to me and it probably gets parsed somewhere - so placing a translation there would have looked kind of dangerous in my eyes. I should have tried it out, though.

    * Are dots allowed in the translated tab name when I do it this way?
    * If I need to refer to that tab elsewhere, I will have to reference it using its translated name, right?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: i18n: Setting a proper name for a new tab Link to this post

    1) No as . is the delimiter. You might want to try it out . As I would have though currently you have Root.Content.TabName so the . signifies a hierarchy. Eg the Content tab of the Base Editor has a sub tab of 'TabName'. so . I wouldn't have though would work but you never know.

    2) You would have to refer to any other references of that tab as "Root.Content."._t('SiteTree.TABSIDE')."" as 'side' and 'neben-inhalte' would be difference to SS so for it to work while switching the 2 you need to use _t('SiteTree.TABSIDE') everywhere.

  • jacobsjensen
    Avatar
    Community Member
    20 Posts

    Re: i18n: Setting a proper name for a new tab Link to this post

    Hi guys,

    willr, I just used your method and it works fine, but when using special characters as ø = ø , as tab name it creates two identical tabs in the cms and puts one of my fields on the main tab...

    Is there a way to make special characters work in tab-names??

    1757 Views
Page: 1
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.