Jump to:

796 Posts in 409 Topics by 304 members


SilverStripe Forums » Widgets » Using i18n in widgets (subclass of Widget) or widget extensions (subclass of DataExtension)

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 470 Views
  • eddieconnecti
    Community Member
    26 Posts

    Using i18n in widgets (subclass of Widget) or widget extensions (subclass of DataExtension) Link to this post

    Trying to get translations to work in widget. But get not the translation

    Directory structure of the widget in the ss root is:

    - widget_test
    -- _config
    --- TestWidget.yml
    -- code
    --- extension
    ---- TestWidgetExtension.php
    --- model
    ---- TestWidget.php
    -- lang
    --- _manifest_exclude
    --- de.yml
    --- en.yml
    -- templates
    -- _config.php


    <?php /* */ ?>


    Example code of TestWidget.php:

       function getCMSFields()
          $fields = new FieldList(
             new TabSet("GeneralTab",
                $tabTemplate = new Tab(
                   $name = 'SubTab',
                   new HeaderField("filters", _t('FormFieldLabels.FILTERS', 'Filters')),   
                   new HeaderField("sorting", _t('FormFieldLabels.SORTING', 'Sorting'))
                $tabRequest = new Tab(
                   $name = 'RequestSettings'
                $tabInfo = new Tab(
                   $name = 'InfoTab'
          $tabTemplate->setTitle(_t('TabLabels.TEMPLATESETTINGS', "Template settings"));
          $tabRequest->setTitle(_t('TabLabels.REQUESTSETTINGS', "Request settings"));
          $tabInfo->setTitle(_t('TabLabels.INFOTAB', "Details"));
          $this->extend('updateCMSFields', $fields);
          return $fields;


    Example code of TestWidgetExtension.php:

    function updateCMSFields(FieldList $fields)
       // Template settings
       // - Filters
       $fields->addFieldToTab('GeneralTab.SubTab', new NumericField("ResultStart", _t('FormFieldLabels.STARTROW', "STARTROW")), "sorting");


    Example code of de.yml:
    STARTROW: "Start at ..."


    The NumericField is rendered, but the label is "STARTROW", instead it should be "Start at ..." Another problem is, that the values of the formfields donĀ“t find their way to the database, but I already posted this in another topic (http://www.silverstripe.org/widgets-2/show/23444)

    Any idea could help!

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.