Hello all:
I’ll turn back to the multilang issue, which was the initial subject of this thread.
What I needed:
- I needed to implement Indexu 5+ (nicely written script!!) in a multilang website (French and English)
- I didn’t care to have an English only backend
- Needed flexibility as not all my entries were multilang...
Here the three steps I implemented to get a multilang frontend:
(1) I’ve simply added the following function at the end of misc.lib.php (before closing tag)
Code:
// ----- MERIDIUM :: Multilang filter -----
function format_text($string) {
$langtarget = array ('EN' => '\1', 'FR' => '\2');
if (!isset($_REQUEST['mlv']))
$langtag = 'EN'; //default lang if not specified
else
$langtag = strtoupper($_REQUEST['mlv']); //set lang
if( ! ( strpos($string,'<'.$langtag.'>')===false ) ) // check if $string is multilang
$string = preg_replace('/<EN>(.*?)<\/EN><FR>(.*?)<\/FR>/', $langtarget[$langtag], $string);
return $string;
}
You'll notice I’ve created a multilang var ($mls) that must appear in your query string (or else default lang)…
(2) When adding links and catedories, I used the following pattern for multilang entries (French or English only entries, use no tags)
Code:
<EN>EnglishString</EN><FR>FrenchString</FR>
Then, all you need to do is use the format_text($yourstringtobeparsed) function for string translation here and there in the category.class.php and link.class.php and you’re done.
Tweaks:
Must be intermediate with PHP to implement this hack as this requires a lot of little mods in a couple of files to call the format_text function at the right places and to hard code de mlv var (if only I knew how to put this var in a session env...)… MySQL queries also need to be tweaks a little for proper sorting of links and categories(pattern matching needed). I will need to adapt the spider link to parse 2 URLs per multilang entry…
With smarty it was pretty easy to call different headers and footer depending on the value of the mlv var.
Code:
<%if $header%>
<%$header%>
<%elseif $smarty.get.mlv == "FR"%>
<%include file="header-fr.html"
title="Browse by categories: $page_title"
meta_keywords="$meta_keywords"
meta_description="$meta_keywords"
%>
<%else%>
<%include file="header.html"
title="Browse by categories: $page_title"
meta_keywords="$meta_keywords"
meta_description="$meta_keywords"
%>
<%/if%>
I though this mod to be straightforward as you can create an IndexU multilang web site (any combination of lang) just in a few minutes without duplicating entries, templates or altering database.
I'm not done yet but at least it's a start. What do you guys think?
Cheers,
Seb