another frontend language version

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
biber2005
Posts: 2
Joined: Mon Mar 29, 2010 11:14 pm

another frontend language version

Post by biber2005 »

Hello, serendipity is my favourite blog software! As a new forum member now a first question: How to install another frontend language, e.g. an english version (not only entries, but the whole stuff; Menu bars have to be translated, too)? Is it necessary to install the whole s9y data pack a second time or is there a more intelligent way of duplicating only index.tpl or so?
Help welcome :-)
biber2005
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: another frontend language version

Post by Don Chambers »

Hmm... we were doing fine right up until you mentioned translating navigation/menu links too. The template you are using (kinetic) has no way to provide multiple languages for the navigation links. Maybe someone else has some good ideas, so I do not want to jump to conclusions just yet since I have never tried to create a site in a second language.

One posssible idea could be subdomains, such as http://en.maindomain.com, http://de.maindomain.com... or maybe http://maindomain.com/en/, etc... Each would be a completely independent blog.

Hopefully those with more multilingual experience will chime in.. :wink:
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: another frontend language version

Post by garvinhicking »

Hi!

One way would be to make use of language constants. That would require people editing the lang_* files of the template to insert their navigation linknames. This is the most clean solution.

Another way is to split the input to use a syntax like this:

Code: Select all

{{!de}}German{{--}}{!en}}English{{--}}
This one is used by the multilingual plugin for some things as well. Then the template's config.inc.php can use a smarty modifier like this:

Code: Select all

function smarty_multiling($msg) {
    function strip_langs($msg) {
        global $serendipity;

        if (!preg_match('@{{@', $msg)) return $msg;

        $language = $serendipity['lang'];
        /* Handle escaping of {} chars. If someone is up for it,
           they're welcome to try and find a better way. As it is,
           this appears to work. */
        $msg = str_replace('\{', chr(1), $msg);
        $msg = str_replace('\}', chr(2), $msg);

        // The explode actually makes sure that each latter array part will end on either the full string end or {{--}
        $parts = explode('{{--}}', $msg);
        $out   = '';
        // Iterate each subblock and inspect if its language matches.
        foreach($parts AS $idx => $match) {
            if (empty($match)) continue; // Last block part, skip it.
            if (stristr($match, '{{!' . $serendipity['lang'] . '}}')) {
                // Current language found. Keep the string, minus the {{!xx}} part.
                $out .= preg_replace('@\{\{!' . $serendipity['lang'] . '\}\}@', '', $match);
            } else {
                // Current language not found. Remove everything after {{!xx}}.
                $out .= preg_replace('@\{\{![^\}]+\}\}.+$@', '', $match);
            }
        }

        $msg = $out;

        /* Put back escaped {} chars */
        $msg = str_replace(chr(1), '{', $msg);
        $msg = str_replace(chr(2), '}', $msg);

        return $msg;
    }
}
$serendipity['smarty']->register_modifier('smarty_multiling', 'smarty_multiling')
and in the template use {$navoptionblabla.bla|@smarty_multiling}.

Then all current languages are evaluated through the index.php?user_language=XX language change method offered by the multilingual plugin.

Using VHosts with language constants is another way, you could use a simple plugin to auto-detect $serendipity['language'] inside serendipity_config_local.inc.php based on the HTTP_Host. Somewhere on this forum I gave examples for this...

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/
Don Chambers
Regular
Posts: 3657
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: another frontend language version

Post by Don Chambers »

Garvin - do you think any of those suggestions are superior to an independent installation for another language, and if so, why?
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: another frontend language version

Post by garvinhicking »

Hi!
Don Chambers wrote:Garvin - do you think any of those suggestions are superior to an independent installation for another language, and if so, why?
Sure, everything superior to duplicate installations, especially if you want translated entries, the same users, a single RSS feed etc... :)

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/
biber2005
Posts: 2
Joined: Mon Mar 29, 2010 11:14 pm

Re: another frontend language version

Post by biber2005 »

Hi Garvin and Don,
thanks a lot for your prompt answers! As a beginner I will try to understand that step for step during the next decades ;-)
Independant installation might fit for the moment with all together two languages needed (english and german), but on the horizon are upcoming wishes to do the same in some more languages. At this point it is clear that one multi-language installation is superior, especially regarding content updates...

Have some sunny easter days
biber2005
Post Reply