Open Source Content Management Framework

Building Multilingual sites with MidCOM template

  1. Setting up the website
  2. Making MidCOM aware of the languages
  3. Automatic language negotiation

Note: This method of building multilingual MidCOM sites has been deprecated in favor of a much simpler multilingual system in MidCOM 2.7 series.

A typical situation with MidCOM sites is that multiple country sites or languages are needed. Here is how to set up these different language subsites in MidCOM template.

Setting up the website

Set up the website normally. Then log into the content authoring interface and create top-level topics for each language you want to have on your site. It doesn't matter what component is used to drive those topics, but very often it is de.linkm.taviewer. The URL name of the topics should be the two letter country code.

The top-level country topics are actually the front pages of different language versions of the site. The site structure can be created freely under them, although it would be recommended to make the site structure quite identical between languages.

Making MidCOM aware of the languages

To tell MidCOM about the languages and country topics on your site you need to change the MidCOM template configuration. This is done by creating a configuration snippet /sitegroup-config/midcom-template/config.

Log into Aegir (or your administrative interface of choice) and go to the Snippets tab. There you should create a sitegroup-config top-level directory to the same sitegroup where the site is in. Then create a midcom-template snippet directory under that. In this directory you can place the configuration PHP code in a config snippet.

Configure the languages used on the site:

// Languages enabled on the site, and information about them
// in format 'URL prefix' => 'Language code'
$GLOBALS['midcom_site']['site_languages_array'] = array(
    'fi' => 'fi', // Finnish
    'en' => 'en', // English
    'ge' => 'ka'  // Georgian
);

// Default language
$midcom_site['default_language_site'] = 'en';
$midcom_site['site_language'] = $GLOBALS['midcom_site']['site_languages_array'][$midcom_site['default_language']];

Set MidCOM's language based on the URL prefix user is in:

if ($_MIDGARD['self'] == $GLOBALS['midcom_site']['uri']) 
{
    // On-site language
    if (   $_MIDGARD['argc'] > 0 
        && array_key_exists($_MIDGARD['argv'][0],$GLOBALS['midcom_site']['site_languages_array'])) 
    {
        $GLOBALS['midcom_site']['site_language'] = $GLOBALS['midcom_site']['site_languages_array'][$_MIDGARD['argv'][0]];
    }
} 
elseif ($_MIDGARD['self'] == $GLOBALS['midcom_site']['uri'].'midcom-admin/ais/') 
{
    // AIS language
    if ($_MIDGARD['argc'] > 0) 
    {

        foreach ($GLOBALS['midcom_site']['site_languages_array'] as $prefix => $code)
        {
            $language_topic = mgd_get_topic_by_name($GLOBALS['midcom_site']['root_topic']->id,$prefix);
            if (   $language_topic
                && (   $language_topic->id == $_MIDGARD['argv'][0]
                    || mgd_is_in_topic_tree($language_topic->id, $argv[0])))
            {
                $GLOBALS['midcom_site']['site_language'] = $code;
            }
        }
    }
}

This is all needed to make a site multilingual. With this setup the root URL of the site can be used for a splash screen presented to users for selecting language.

Automatic language negotiation

As an option, you can also utilize HTTP Language Negotiation for automatically directing the user to correct language version of the site. To do this, add the following to the midcom-template config snippet:

// Language negotiation
if ($_MIDGARD['uri'] == $GLOBALS['midcom_site']['uri']) 
{
    if ($_SERVER[HTTP_ACCEPT_LANGUAGE])
    {
        $langstr = explode(',',$_SERVER[HTTP_ACCEPT_LANGUAGE]);

        if (is_array($langstr)) 
        { 
            foreach ($langstr as $language) 
            {
                $language = substr($language,0,2);

                if (array_key_exists($language, $GLOBALS['midcom_site']['site_languages_array'])) 
                {
                    header('Location: '.$GLOBALS['midcom_site']['uri'].$language.'/'.$suffix);
                    exit;
                } 
            }
        }
    }
    // No language preferences matched, go to default language
    header('Location: '.$GLOBALS['midcom_site']['uri'].$GLOBALS['midcom_site']['default_language'].'/'.$suffix);
    exit();
}
Tagged
multilang
midcom-2.7.0
Designed by Nemein, hosted by Kafit