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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

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

Widget with MultiLanguage content


Go to End


8 Posts   6050 Views

Avatar
wazzup

Community Member, 1 Post

2 March 2010 at 2:48am

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

Avatar
klikhier

Community Member, 150 Posts

11 June 2010 at 6:21am

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

Avatar
m-phil

Community Member, 37 Posts

28 August 2010 at 3:15am

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

Avatar
m-phil

Community Member, 37 Posts

20 September 2010 at 9:26pm

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.

Avatar
m-phil

Community Member, 37 Posts

29 October 2010 at 7:55pm

Edited: 29/10/2010 9:25pm

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();
		}
	}

Avatar
ptasker

Community Member, 1 Post

24 February 2011 at 5:27am

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

Avatar
m-phil

Community Member, 37 Posts

29 April 2011 at 10:59pm

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?

Avatar
swaiba

Forum Moderator, 1899 Posts

6 July 2011 at 12:05am

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();
		}
	}
}