WPML and styling support

This topic contains 10 replies, has 3 voices, and was last updated by  Stephen Harris 11 years, 4 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2714

    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
    #2715

    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
    #2716

    Cool, that would be great! 😉

    postrel
    #2717

    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
    #2721

    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
    #2724

    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
    #2725

    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
    #2726

    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
    #2727

    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
    #2728

    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.

    gettext setup

    postrel
    #2740

    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
Viewing 11 posts - 1 through 11 (of 11 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.