I needed to create a site with multiple languages and decided to use midgards new multilang system for it.
I encountered few problems along the way so I describe what I did, for everyone who would like to use the multilang feature.
First of I created a normal site (at this point I wasn't aware there will be other languages also) ie. http://multilang-example.com with create-sitegroup & create-host scripts (One could also use midgard sitewizard).
After that I created the sitestructure just like I would do on any site.
And don't forget to set virtual host for your site. (ie. use datagard to create new virtual host)
Before you can use multilang:
- Get the latest midgard and midcom
( Install a hotfix for your midgard-core)
After installing the hotfix (I used apt-get update , apt-get --reinstall install libmidgard9) you have to edit your hosts config a bit.
This can be done in many ways, but I used spider-admin and browsed to my new host's ROOT page and edited the code-init element by adding a new row to the top:
$GLOBALS['midcom_config_local']['i18n_multilang_strict'] = false;
And I also made the site's url change automatically to default lang if no lang had been determined in the url: (This is added to the same page element after $_MIDCOM->codeinit(); )
---CODE
$curr_url = $_MIDCOM->_parser->fetch_URL();
$default_lang = "en";
$base_url = "http://multilang-example.com";
$hosts = $_MIDCOM->i18n->get_language_hosts();
foreach($hosts as $k => $host) {
if($host->prefix != "" && $host->lang == 0) {
$default_lang = str_replace("/","",$host->prefix);
}
}
if($curr_url == $base_url) {
header('Location: '.$curr_url.$default_lang.'/'.$suffix);
exit();
}
---/CODE
After this I created new hosts for each language (also for my default language) with spider-admin, giving each host the same style,main page and sitegroup than the original. Only difference at this point to the original is the prefix:
- http://multilang-example.com/en
- http://multilang-example.com/fi
- http://multilang-example.com/se
Then you need to set the proper lang id for these hosts. For this I used phpMyAdmin, but one could use any sql access methods to update the host rows.
First off find the lang id's you want to use by searching the midgard_language table in database (explained in the multilang doc at Midgard site).
So edit your newly created hosts and set the lang column to the corresponding lang id. You want to keep your default lang to 0 (in this case the english), so you would end up with something like this (having four hosts with different prefixes):
- http://multilang-example.com (Lang 0)
- http://multilang-example.com/en (Lang 0)
- http://multilang-example.com/fi (Lang 44)
- http://multilang-example.com/se (Lang 151)
Now you are ready to go.
Just log in to your default lang site and on another browser window (or tab) login to some other lang. And start editing...
You will see that the site structure is the same in all of the sites and when you edit your default (lang 0) site you get that same content on the other languages also.
If you don't wan't to show untranslated content in other sites, just set the previous config row to $GLOBALS['midcom_config_local']['i18n_multilang_strict'] = true;
Hopefully this helps someone and saves him the few days I struggled with this to get it working.
If I have forgotten something or find an easier way of doing things, I'll let you now.
