SidebarHider to toggle with Language change

Creating and modifying plugins.
Post Reply
chrissie
Regular
Posts: 11
Joined: Sat Mar 03, 2007 5:37 am
Location: Perth, AU
Contact:

SidebarHider to toggle with Language change

Post by chrissie »

Hi, I would love to say thankyou so much for such a fantastic piece of software. I'm using s9y for one of my other sites and am now setting it up for my new site.

I have a couple of questions to do with multiple language support.

1. First is there any way to have the template change when a certain language is selected?

2. Is it possible to edit the SidebarHider event plugin to have a language field as well?

3. If #2 is possible would s9y allow me to use multiple instances of the same sidebar plugin with different content in each instance?

4. If #2 is not possible is there anyway to set the sidebar plugins to show the title and content change depending on the language chosen?


I hope I've made some kind of sense here, if not please ask me to clarify anything you need to know.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: SidebarHider to toggle with Language change

Post by garvinhicking »

Hi!
1. First is there any way to have the template change when a certain language is selected?
You could do this with a simple event plugin (which needs to be executed AFTER the language selection plugin):

Code: Select all

<?php
if (IN_serendipity !== true) die ("Don't hack!");

class serendipity_event_languagetemplate extends serendipity_event {
    var $title = 'Template Language';

    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',        'Template Language');
        $propbag->add('description', '');
        $propbag->add('stackable',   false);
        $propbag->add('author',      'Garvin Hicking');
        $propbag->add('version',     '0.1');
        $propbag->add('event_hooks', array('frontend_configure' => true));
    }

    function generate_content(&$title) {
        $title = $this->title;
    }

    function event_hook($event, &$bag, &$eventData) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
              case 'frontend_configure':
                switch($serendipity['lang']) {
                    case 'de':
                        $serendipity['template'] = 'german';
                        break;

                    case 'en':
                    default:
                        $serendipity['template'] = 'default';
                        break;
                }
                return true;
                break;
            }
        }
        return false;
    }
}
2. Is it possible to edit the SidebarHider event plugin to have a language field as well?
Yes, it is possible to edit that plugin. :-)
3. If #2 is possible would s9y allow me to use multiple instances of the same sidebar plugin with different content in each instance?
That depends on the plugin. Some sidebar plugins can only be installed once!

HTML nuggets for example can be installed any amount you like.
4. If #2 is not possible is there anyway to set the sidebar plugins to show the title and content change depending on the language chosen?
You can patch the plugins to not use configured titles in the plugins for $title, but instead constants that depend on the selected language, just like all other constants a plugin uses.

Just like the basic bundled plugins for example have a fixed title "Comments" that adapts to the language because its a constant.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply