Jump to:

791 Posts in 369 Topics by 303 members

Widgets

SilverStripe Forums » Widgets » Widget with MultiLanguage content

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 4022 Views
  • wazzup
    Avatar
    Community Member
    1 Post

    Widget with MultiLanguage content Link to this post

    Hello.

    I have been trying to make multi language widget. The problem is that, when I choose another language (not English) widget doesn't get data according this language.

    Index page (where I added widget) getting new locale after language switch, but widget not. If I am right widget doesn't have locale field at all.

    How can I get site locale in widget? Any suggestions?

    Thank you a lot

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Widget with MultiLanguage content Link to this post

    This most likely occured when

    1. Create page in language A
    2. 'Duplicate' page in language B by means of the 'Translations' tab

    In this case the same WidgetAreaID is used for two different pages. Solution I found is to alter the database (create new row in WidgetArea table and change SidebarID in Page table).

    Happend to me on SS2.3.7

  • m-phil
    Avatar
    Community Member
    33 Posts

    Re: Widget with MultiLanguage content Link to this post

    The problem is already in 2.4, any solutions? Or where is the function to create the new translated page? There we only need to add the creation handler for widget areas...

  • m-phil
    Avatar
    Community Member
    33 Posts

    Re: Widget with MultiLanguage content Link to this post

    OK, I haven't activated 'Translatable' for widgets...

    Object::add_extension('Widget', 'Translatable');
    Object::add_extension('WidgetArea', 'Translatable');

    But there is also a bug because when adding a widget now, it will be created for 'en_US' instead of the current language
    Here is my config:

    Translatable::enable();
    Translatable::set_default_lang('de_DE');
    Translatable::set_default_locale('de_DE');

    // Set the site locale
    i18n::enable();
    //i18n::set_locale('de_DE');
    i18n::set_default_lang('de_DE');
    i18n::get_tinymce_lang('de_DE');

    I have german (de_DE) and english (en_GB!) pages and there are no problems by switching the language, only the widget areas doesn't work probably. Pages will be save in their language and widgets as Locale = 'en_US'?! Because of that I can't see the added widgets in the backend.

  • m-phil
    Avatar
    Community Member
    33 Posts

    Re: Widget with MultiLanguage content Link to this post

    OK I have it by adding simple auto correction on before saving a widget
    in sapphire/widgets/Widget.php

       function onBeforeWrite() {
          parent::onBeforeWrite();
          
          // Set locale from the currently choosen language locale
          if($this->Locale != Translatable::get_current_locale()) {
             $this->Locale = Translatable::get_current_locale();
          }
       }

  • ptasker
    Avatar
    Community Member
    1 Post

    Re: Widget with MultiLanguage content Link to this post

    I've opened a ticket to address this issue. http://open.silverstripe.org/ticket/6470

  • m-phil
    Avatar
    Community Member
    33 Posts

    Re: Widget with MultiLanguage content Link to this post

    Hey, nothing happened for this bug, but in my opinion the multilingual functionallity is very important for a CMS...
    Does anyone know, when it will be fixed?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Widget with MultiLanguage content Link to this post

    many thanks for this thread!

    I've done the following to avoid hacking the core...

    _config.php

    Object::add_extension('Widget', 'WidgetExtension');

    WidgetExtension.php

    class WidgetExtension extends DataObjectDecorator {
       function onBeforeWrite() {
          parent::onBeforeWrite();

          // Set locale from the currently choosen language locale
          if($this->owner->Locale != Translatable::get_current_locale()) {
             $this->owner->Locale = Translatable::get_current_locale();
          }
       }
    }

    4022 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.