Possibility of adding multilingual navbar support?

Discussion corner for Developers of Serendipity.
Post Reply
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Possibility of adding multilingual navbar support?

Post by wesley »

Recently, I started using a theme that uses global navigation on my multilingual blog. One thing I would have liked to see was having an option to show different navbar items depending on the language selected. Basically, providing navbar items in appropriate languages.

Would it be possible to tack on a language selection box on the existing framework, or should I just do away with the global navigation and have a custom array just for the theme?
I make s9y plugins, too.
My s9y blog depends on them. :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Possibility of adding multilingual navbar support?

Post by garvinhicking »

I believe adding a language selection checkbox that toggles additional input fields there would be quite complicated.

I'd rather suggest you create one additional menu item in the configuration for each language, and then depending on the language you later pass the corresponding menu item to the output.


HTh,
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/
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Possibility of adding multilingual navbar support?

Post by wesley »

That sounds sensible. I'll give it a try. Thanks.
I make s9y plugins, too.
My s9y blog depends on them. :)
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Possibility of adding multilingual navbar support?

Post by wesley »

Alright, I got it working! I made it so that you get a dropdown box for each navigation item's language. You can pick "All" or a specific language, like the current multilingual HTML nugget plugin.
multilingual_menu.png
multilingual_menu.png (46.02 KiB) Viewed 14608 times
My website http://tool-box.info/blog/ has five menu items assigned to each of the two languages it's in (English and Korean) for a total of ten. Switching the language will show the appropriate five.
I make s9y plugins, too.
My s9y blog depends on them. :)
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Possibility of adding multilingual navbar support?

Post by Timbalu »

I wish your dancing panda could stand still. Its hard to concentrate with this up and down... :)

Maybe you can give a working code example for others to build this into their theme too?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
wesley
Regular
Posts: 197
Joined: Sun Jul 10, 2005 11:15 am
Contact:

Re: Possibility of adding multilingual navbar support?

Post by wesley »

It was a quick-and-dirty implementation involving adding of a variable into the existing array.

In the config.inc.php file, instead of calling out this function:

Code: Select all

serendipity_loadGlobalThemeOptions($template_config, $template_loaded_config, $template_global_config);
I added a block of code that does the same thing, plus accepting a language variable:

Code: Select all

$navlinks = array();
$conf_amount = array(
    'var'           => 'amount',
    'name'          => NAVLINK_AMOUNT,
    'type'          => 'string',
    'default'       => '5',
    'scope'         => 'global'
);
$template_config[] = $conf_amount;
if (!isset($template_loaded_config['amount']) || empty($template_loaded_config['amount'])) {
    $template_loaded_config['amount'] = $conf_amount['default'];
}

for ($i = 0; $i < $template_loaded_config['amount']; $i++) {
    $navlinks[] = array(
        'title' => $template_loaded_config['navlink' . $i . 'text'],
        'href'  => $template_loaded_config['navlink' . $i . 'url'],
        'language' => $template_loaded_config['navlink' . $i . 'lang']
    );
    $template_config[] = array(
        'var'           => 'navlink' . $i . 'text',
        'name'          => NAV_LINK_TEXT . ' #' . ($i+1),
        'type'          => 'string',
        'default'       => 'Link #' . ($i+1),
        'scope'         => 'global'
    );
    $template_config[] = array(
        'var'           => 'navlink' . $i . 'url',
        'name'          => NAV_LINK_URL . ' #' . ($i+1),
        'type'          => 'string',
        'default'       => '#',
        'scope'         => 'global'
    );
    $template_config[] = array(
        'var'           => 'navlink' . $i . 'lang',
        'name'          => INSTALL_LANG . ' #' . ($i+1),
        'type'          => 'select',
        'default'       => 'all',
        'select_values' => array('all' => COMMENTS_FILTER_ALL,
                    			 'en' => 'English',
                    			 'de' => 'German',
                    			 'da' => 'Danish',
                    			 'es' => 'Spanish',
                    			 'fr' => 'French',
                    			 'fi' => 'Finnish',
                    			 'cs' => 'Czech (Win-1250)',
                    			 'cz' => 'Czech (ISO-8859-2)',
                    			 'nl' => 'Dutch',
                    			 'is' => 'Icelandic',
                    			 'se' => 'Swedish',
                    			 'pt' => 'Portuguese Brazilian',
                    			 'pt_PT' => 'Portuguese European',
                    			 'bg' => 'Bulgarian',
                    			 'hu' => 'Hungarian',
                    			 'no' => 'Norwegian',
                    			 'ro' => 'Romanian',
                    			 'it' => 'Italian',
                    			 'ru' => 'Russian',
                    			 'fa' => 'Persian',
                    			 'tw' => 'Traditional Chinese (Big5)',
                    			 'tn' => 'Traditional Chinese (UTF-8)',
                    			 'zh' => 'Simplified Chinese (GB2312)',
                    			 'cn' => 'Simplified Chinese (UTF-8)',
                    			 'ja' => 'Japanese',
                    			 'ko' => 'Korean'),
        'scope'			=> 'global'
    );
}
$serendipity['smarty']->assignByRef('navlinks', $navlinks);
At first, I added the code for the language variable after calling out serendipity_loadGlobalThemeOptions, but then the dropdown box for the language appeared together at the bottom of the page, so I went with this way.

Then in the index.tpl of the theme, the navbar rendering implements "navlink.language" like so:

Code: Select all

<ul>
{foreach from=$navlinks item="navlink"}
    {if $navlink.language!='all'&&$navlink.language!=$lang}
    {elseif $navlink.title!=""&&$navlink.href!=""}
        <li>
        {if $currpage==$navlink.href or $currpage2==$navlink.href}
            <span>
        {else}
            <a href="{$navlink.href}">
        {/if}
        {$navlink.title}
        {if $currpage==$navlink.href or $currpage2==$navlink.href}
            </span>
        {else}
            </a>
        {/if}
        </li>
    {/if}
{/foreach}
</ul>
The initial {if}{elseif} should filter out a menu item if it's not assigned to the correct language.

P.S. The avatar is the dancing badger from the 2003 fiash animation that was quite famous back then. :)
I make s9y plugins, too.
My s9y blog depends on them. :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Possibility of adding multilingual navbar support?

Post by garvinhicking »

Nice! Thanks for sharing the code. Even though it's not the most elegant solution due to s9y's restriction, I think it is cool to be able to workaround that :-)
# 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