Page 1 of 1

Multi-Languages to change the site template?

Posted: Thu Oct 11, 2007 9:33 am
by Col. Kurtz
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.

Re: Multi-Languages to change the site template?

Posted: Thu Oct 11, 2007 10:51 am
by garvinhicking
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

Posted: Fri Oct 12, 2007 9:32 am
by Col. Kurtz
sounds interesting, yet its beyond my skills. I will do my porting for the default template first and think about a bulletproof port later

Posted: Fri Oct 12, 2007 10:53 am
by garvinhicking
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

Posted: Wed Nov 28, 2007 11:14 am
by williamts99
When using the bulletproof template how would I go about using definitions from lang_XX.inc.php for my navbar links, title and description?

Posted: Wed Nov 28, 2007 1:10 pm
by garvinhicking
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

Posted: Wed Nov 28, 2007 3:48 pm
by williamts99
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}

Posted: Wed Nov 28, 2007 6:51 pm
by garvinhicking
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

Posted: Sat Dec 01, 2007 1:33 am
by williamts99
Thanks, this is exactly what I needed.