ManiaLib 1.0b1 API Reference

File/libraries/LangEngine.class.php

Description

Internationalization

ManiaLib provides a simple way to internationalize your application. The good news is it uses the same dictionary format as the dictionary feature implemented in ManiaLinks. The advantage of using the internationalization features of ManiaLib over classic Manialink dictionaries is the ability of making dynamic sentences (eg. "Hello 'login'!" where login is from a variable).

How to use it?

First, make sure that the parameter "lang" is in the session. To achieve that, you need to use a link with "addplayerid" and then save the parameter in the session. If you use the MVC framework, you can add the RegisterRequestParametersFilter to your controller (it will look for the lang parameter in the URL and save it automatically in the session).

Then, put your dictionary files in the APP_LANGS_PATH directory. You must use same structure as classic Manialink dictionary, but you can add placeholders for variables using '[1]', '[2]', etc. (without the quotes).

  1.   <?xml version="1.0"?>
  2.   <dico>
  3.       <language id="en">
  4.           <hello_world>Hello World!</hello_world>
  5.           <hello_login>Hello [1] !</hello_login>
  6.           <the_xx_is_yy>The [1] is [2].</the_xx_is_yy>
  7.       </language>
  8.   </dico>

Then you can use the translations in your views using the __() function:

  1.   __("hello_world")// returns "Hello world!"
  2.   __("hello_login""gou1")// Returns "Hello gou1!"
  3.   __("the_xx_is_yy""car""blue")// Returns "The car is blue."
  4.   __("Bla bla bla")// Returns "Bla bla bla", ie. the word ID itself when it is not found.

You can also internationalize dates:

  1.   $timestamp time();
  2.   __date($timestamp)// Returns, for example: "Friday, July 3rd 2009"

Functions
__ (line 196)

i18n message

To use with APP_LANG_ENGINE_MODE_DYNAMIC

Example:

  1.  echo __("hello_world");
  2.  echo __("hello_login"$someLogin);

string __ (string $textId)
  • string $textId
__date (line 228)

i18n date

To use with APP_LANG_ENGINE_MODE_DYNAMIC

string __date (int $timestamp)
  • int $timestamp: Unix timestamp