Open Source Content Management Framework

MgdSchema Create language context

  1. Unknown language
  2. Default language
  3. Example
  4. Translation's language context
  5. Example

Midgard provides three different types of languages:

  • Unknown language ( backward compatible ) identified by 0
  • Default language context
  • Settable translation's language context

Unknown language

Every Midgard appllication ( and internal connection handler ) is initialized with unknown language 0. This value is set as default language and language context values. If application doesn't have to use Multilingual contents or should be fully backward ( < Midgard 1.8alpha3 ) compatible , then there is no need to set default or context language.

Default language

Default language is designed for applications for which content should be created always in some explicit language , or objects in some language ( e.g. 'fi' ) should be exported from database and imported to another one with the same language.

Setting default language:

void mgd_set_default_lang(int lang_id);

Example

<? $qb = new midgardquerybuilder("midgard_language"); $qb->add_constraint("code", "=", "fi"); $ret = $qb->execute(); if($ret) mgd_set_default_lang($ret0>id); ?>

This function should be called once at application startup. It sets internal default language and language context to value passed as function parameter. If object has content in lang 0 ( unknowm ) and in lang fi, then only content with lang 0 will be queried from database. So , this function just limits returned objects to only one language.

Translation's language context

Translation's language context is designed for content translation. If the aplication uses content in some explicit language ( e.g. 'fi' ) , and content should be also translated to English , then application's language context for translation should be set.

Setting language context:

void mgd_set_lang(int lang_id);

Example

<?

$qb = new midgardquerybuilder("midgard_language");
$qb->add_constraint("code", "=", "en");
$ret = $qb->execute();

if($ret) 
   mgd_set_lang($ret0>id); 
?>

If both functions have been invoked and default language is not the same as translation language context , then object's content is returned using such convention (default language is D , translation language is T ):

  • content with lang T is returned if content with lang D and lang T exists
  • content with lang D is returned if content with lang T doesn't exists
Designed by Nemein, hosted by Kafit