language specific blog title, description

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
selva
Regular
Posts: 5
Joined: Fri Mar 26, 2004 1:37 am
Contact:

language specific blog title, description

Post by selva »

I am translating the language strings to "tamil" language. A question I ran into:-

When the visitor clicks on the language specific link to read a post in tamil, is there a way I can display the blog title/description in tamil too (assuming I have the translation somewhere)? At the moment, the blog title/description seems to be set for the blog as a whole in the database (config table) irrespective of user or a specific post.

I know I haven't described the question clearly (no coffee at home). I'll be happy to elaborate if someone asks.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: language specific blog title, description

Post by garvinhicking »

That's right, the blog title/description cannot be changed language dependently.

You could code your own plugin that sets those variables depending on the language, though.

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/
selva
Regular
Posts: 5
Joined: Fri Mar 26, 2004 1:37 am
Contact:

Post by selva »

thanks, garvin. I've got a learning curve (need to learn a bit of PHP and how to write plugins for s9y). I'll work on that.

A few questions.
1.Which tables should I look at?
2.Should I work on updating the multi-lingual plugin? Or should this be a new plugin by itself?
3. Is there a event hook to use to throw the language specific blog title?

thanks for the pointers.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi Selva!

I think you wouldn't need specific tables, you can save the specific language
options/names in the general serendipity_config db container.

I would change $serendipity['blogTitle'] and $serendipity['blogDescription'] in
the frontend_configure hook.

Here is a rough draft for such a plugin, which you could built on. Integrating
it with the multilingual plugin sounds like a good idea:

Code: Select all

<?php # $Id: serendipity_event_multilingual.php,v 1.23 2005/11/04 19:54:31 garvinhicking Exp $

class serendipity_event_multilingualtitle extends serendipity_event
{
    function introspect(&$propbag)
    {
        global $serendipity;

        $propbag->add('name',          'Multilingual Titles');
        $propbag->add('description',   '');
        $propbag->add('stackable',     false);
        $propbag->add('author',        'Garvin Hicking');
        $propbag->add('version',       '1.0');
        $propbag->add('configuration', array('title_de', 'title_en', 'title_fr'
                                             'desc_de', 'desc_en', 'desc_fr'));
        $propbag->add('event_hooks',    array(
            'frontend_configure' => true,
        ));
        $this->dependencies = array('serendipity_event_multilingual' => 'keep');
    }

    function introspect_config_item($name, &$propbag) {
        global $serendipity;
        if (preg_match('@(title|desc)_(.+)@', '', $keym)) {
            if ($keym[1] == 'title') {
                $propbag->add('type',        'string');
                $propbag->add('name',        'Enter blog title for language ' . $keym[2]);
                $propbag->add('description', '');
                $propbag->add('default',     $serendipity['blogTitle']);
            } elseif ($keym[1] == 'desc') {
                $propbag->add('type',        'string');
                $propbag->add('name',        'Enter blog description for language ' . $keym[2]);
                $propbag->add('description', '');
                $propbag->add('default',     $serendipity['blogDescription']);
            }
            return true;
        }
        
        return false;
        switch($name) {
            case 'copytext':
                break;
            default:
                    return false;
        }
        return true;
    }

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

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

        $hooks = &$bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch($event) {

                case 'frontend_configure':
                    $check_title = $this->get_config('title_' . $serendipity['lang'], '');
                    $check_desc  = $this->get_config('desc_' . $serendipity['lang'], '');

                    if (!empty($check_title) {
                        $serendipity['blogTitle'] = $check_title;
                    }
                    if (!empty($check_desc) {
                        $serendipity['blogDescription'] = $check_desc;
                    }

                    break;

                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
}

/* vim: set sts=4 ts=4 expandtab : */
(The code is untested and might have parse errors...)

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