Hi Stephen,
Could you please wrap the widget titles in gettext calls to make them translatable in multilingual setups? For example, line 113 in class-eo-event-list-widget.php:
echo $before_title.esc_html(__($instance['title'],'eventorganiser')).$after_title;
In the same file, could you please wrap the start date and time in span tags (or else) and attribute some class for easier styling? Line 179:
$template = "<a title='%event_title_attr%' href='%event_url%'>%event_title%</a> "."".__('on','eventorganiser')." %start{{$date}}{{$time}}%"."";
Thanks!
Maxim
Sure :). Might be a chance to introduce microformats (http://support.google.com/webmasters/bin/answer.py?hl=en&answer=164506).
Since these changes are minor will try to get them in for 1.6.2
Stephen Harris
Cool, that would be great! 😉
postrel
Also – you can replace the default template using the template field,,,
(In 1.7 I’m planning on adding an alternative – a dropdown where you can select a template file)
Stephen Harris
Thanks for the hint! Do you mean I can place the template files (such as archive-event.php) in my theme folder? But it doesn’t work for widget templates, does it?
postrel
That’s right – for the widget you use a template place holder.
But the idea is that I’ll be adding a drop-down that will list template files specifically designed for the widget. The plugin will come with some default templates, and these too will be able to be copied into your theme and edited. You’ll also be able to add your own additional templates into the theme. (e.g. you may want one widget to list events in a table, another in a list, and yet another which involves some form of complex logic).
The ‘placeholder’ option will still be available since not everyone will feel up to manipulating template files.
Stephen Harris
Maxim,
I’ve just noticed what you’ve meant by passing titles through gettext calls. You can’t do the following:
__($instance['title'])
you can only pass strings to the gettext functions and not variables… (see http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/)
Stephen Harris
Well, it works fine for me using WPML and their String Translation tool. You should not pass variables to the gettext functions if you aim at an automatic translation (or internationalisation). But if you pick up the strings manually, why not?
postrel
How would you translate it when passing through gettext? Are you using a filter somewhere to change the content depending on the language set? If so, I could apply the filter widget_title
(I probably should do anyway)? You can also filter the $instance
array at widget_display_callback
(https://github.com/WordPress/WordPress/blob/3.5/wp-includes/widgets.php#L179). Either of these suffice?
I’m concerned about passing a variable to gettext because of this line:
Bottom line: Inside all translation functions, no PHP variables are allowed in the strings, for any reason, ever. Plain single-quoted strings only.
I haven’t looked into what problems it could cause if I ignored that advice – but he puts it rather strongly.
Stephen Harris
Yes, the WPML plugin applies filters to change the content based on the language. I don’t really know now if either of your solutions will suffice, I’ll look into it. Please find in the attached image the way I’ve set up the event list widget.
postrel
Seems like applying widget_title
would resolve this… http://wpml.org/faq/getting-string-translation-to-work/
E.g.
echo $before_title.apply_filters('widget_title',$instance['title']).$after_title;
Does that work?
Stephen Harris