Multi-Languages to change the site template?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Col. Kurtz
Regular
Posts: 450
Joined: Thu May 26, 2005 10:43 am
Location: Bonn, Germany
Contact:

Multi-Languages to change the site template?

Post by Col. Kurtz » Thu Oct 11, 2007 9:33 am

I've come across this problem: I want to run a site in English and German. For some other website I use the Multilingual Entries plugin together with some Language Specific HTML Nuggets to display the dynamic content. And well that kinda works, I can display almost everything in both languages.
But the thing that I am not satisfied with is the fact that the static basic site layout can only be done in one language. I'm talking about menu items, header/footers... those things that appear in the index.tpl.
Is it possible to change the multilingual plugin in a way that it also changes the site template in the same way this is done with categories? (Properties/Templates of categories plugin) So I can do a version of the style in both languages.
Marc

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Multi-Languages to change the site template?

Post by garvinhicking » Thu Oct 11, 2007 10:51 am

Hi!

You can change the template by using a config.inc.php and using constants for language abstraction. The bulletproof template for example does that with lang_XX.inc.php files. The selected language will be included based on the visitors language setting.

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/

Col. Kurtz
Regular
Posts: 450
Joined: Thu May 26, 2005 10:43 am
Location: Bonn, Germany
Contact:

Post by Col. Kurtz » Fri Oct 12, 2007 9:32 am

sounds interesting, yet its beyond my skills. I will do my porting for the default template first and think about a bulletproof port later
Marc

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Fri Oct 12, 2007 10:53 am

Hi!

Actually it's really easy, just look at it once. It's much less complex than you think, and it saves time if you do it right the first time :)

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/

williamts99
Regular
Posts: 30
Joined: Sat Dec 10, 2005 11:50 pm
Contact:

Post by williamts99 » Wed Nov 28, 2007 11:14 am

When using the bulletproof template how would I go about using definitions from lang_XX.inc.php for my navbar links, title and description?

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Wed Nov 28, 2007 1:10 pm

Hi!

If inside lang_XX.inc.pphj you have:

Code: Select all

define('YOUR_VAR', 'Blabla');


you can use this in your .tpl files:

Code: Select all

{$CONST.YOUR_VAR}


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/

williamts99
Regular
Posts: 30
Joined: Sat Dec 10, 2005 11:50 pm
Contact:

Post by williamts99 » Wed Nov 28, 2007 3:48 pm

So I was looking at /bulletproof/ tpl files and found index.tpl hold part of what I would use.

Code: Select all

<!-- #serendipity_banner: this is the header area. it holds the blog title and   -->
        <!--                      description headlines                                  -->
        <div id="serendipity_banner">
            <h1><span class="{if $template_option.firbtitle == 'false'}in{/if}visible"><a class="homelink1" href="{$serendipityBaseURL}">{$head_title|@default:$blogTitle|truncate:80:" ..."}</a></span></h1>
            <h2><span class="{if $template_option.firbdescr == 'false'}in{/if}visible"><a class="homelink2" href="{$serendipityBaseURL}">{$head_subtitle|@default:$blogDescription}</a></span></h2>
        </div>
        <div id="serendipity_below_banner"></div>

        {if $template_option.sitenavpos == 'below'}


So for the site name and description I changed $blogTitle and $blogDescription with $CONST.CUST_LANG_TITLE and $CONST.CUST_LANG_DESC respectively and that worked perfectly.
For others reading this, don't forget to add the definitions to each language file.

With the following code though, it seems like I would have to call the definition from somewhere else. The question would be where would I change it for the site nav links?

Code: Select all

            <!-- #sitenav: this holds a list of navigational links which can be customized   -->
            <!--           in the theme configurator                                         -->
            <a name="skipnav"></a>
            <div id="sitenav" class="snbelow">
                <ul>
                    {foreach from=$navlinks item="navlink" name="navbar"}
                        <li class="{if $currpage==$navlink.href}currentpage{/if}{if $smarty.foreach.navbar.first} navlink_first{/if}{if $smarty.foreach.navbar.last} navlink_last{/if}"><a href="{$navlink.href}" title="{$navlink.title}">{$navlink.title}</a></li>
                    {/foreach}
                </ul>
                <!-- quicksearch option in the navigational link menu bar only when navbar is    -->
                <!-- above or below the banner                                                   -->
                {if $template_option.sitenav_quicksearch == 'true'}
                    <form id="navbarsearchform" action="{$serendipityBaseURL}" method="get"><input type="hidden" name="serendipity[action]" value="search" /><input alt="{$CONST.QUICKSEARCH}" type="text" name="serendipity[searchTerm]" value="{$CONST.QUICKSEARCH}..." onfocus="if(this.value=='{$CONST.QUICKSEARCH}...')value=''" onblur="if(this.value=='')value='{$CONST.QUICKSEARCH}...';" /></form>
                {/if}
            </div>
        {/if}

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Wed Nov 28, 2007 6:51 pm

Hi!

That's harder, because the title of nav links are maintained through the admin interface.

For that to use langauge abstraction, you'd actually need to edit the template's config.inc.php file and hardcode the navlink item names there. This is all a bit awkward to fill in.

Inside config.inc.pho you have this:

Code: Select all

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']
    );


This is what you need to replace with constants, something like this:

Code: Select all

for ($i = 0; $i < $template_loaded_config['amount']; $i++) {
    $navlinks[] = array(
        'title' => constant('NAVLINK' . $i . 'TEXT'),
        'href'  => $template_loaded_config['navlink' . $i . 'url']
    );


Then inside your lang_XXX.php files you'd need this:

Code: Select all

@define('NAVLINK1TEXT', 'Your navitem 1 title');


Then you have that constant differently for each language file, and the navlinks will fetch the constant from that file and put into the smarty $navlinks array by relaying it through that constant.

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/

williamts99
Regular
Posts: 30
Joined: Sat Dec 10, 2005 11:50 pm
Contact:

Post by williamts99 » Sat Dec 01, 2007 1:33 am

Thanks, this is exactly what I needed.

Post Reply