Open Source Content Management Framework

Midgard and Multilingual content

  1. MultiLang and MgdSchema objects
  2. Multilingual sites without MultiLang
  3. MultiLang API for PHP development
    1. MultiLang functions and methods
    2. Deprecated methods and functions

With MultiLang, each Midgard object can have content in many languages. The MultiLang system has been integrated into Midgard's new MgdSchema system making it easy to make any content object translateable.

MultiLang and MgdSchema objects

You can define new MultiLang-capable MgdSchema types and define structure attributes and content attributes for them. For more information, read MgdSchema and multilingual content.

Multilingual sites without MultiLang

Of course, you can handle multilingual content without using these features. For example, you can use MidCOM template. Here, you create one object for every language variant of every content item. The only drawback of this approach: If you want a site structure that is consistent across languages, you need to keep track of it yourself.

Additionally, the parameter and attachment objects can be tagged as belonging to a specific language.

MultiLang API for PHP development

Currently, on the PHP level, Midgard objects can only have content in one language at a time. But as explained above, they can have content in many languages in the database. The language used for the object at a time is governed by the globally set current language, an id of a midgard_language object. By default, the language setting is 0, meaning default language.

The current language setting is globally available on PHP level. It can be read by the mgd_get_lang function. The current language can be set in different ways:

  • midgard-apache sets the language according to the lang field of the current host.
  • mgd_set_lang($lang) sets the language. It can be called any number of times during processing of a request. You can not reset the language of the current page or any preparsed page- and style-elements, however. They are preparsed by midgard-apache, before mgd_set_lang can be called.

When an object is instantiated from the database, the current language determines which content is read. If there is no content in the current language, the object cannot be instantiated.

When an new object is created in the database, the current language determines in which language its content is stored.

When an already existing object is updated in the database, its content is updated in the language it was read from (this is stored in the lang property)

All objects are guaranteed to have a content record in the default language, so listing objects can be achieved by calling mgd\_set\_lang(0) and then calling the list function. To find out for which languages an object has any content defined, you can call the $object->get_languages() method.

MultiLang functions and methods

Deprecated methods and functions

  • mgd_get_object_by_guid_all_langs - Get all language versions of an object
  • $object->create_content - Create new language version of an object
  • $object->delete_content - Delete a language version of an object
  • $object->update_content - Update a language version of an object
Designed by Nemein, hosted by Anykey