Class it_text:

/**
 * Constructor
 * Loads all texts.php in include path for translated labels. Singleton; if instanciated mutiple times, texts are merged
 * Example texts.php: <?php return array('_' => array('en'=>"English", 'de'=>"Deutsch"), 'edit'=>array('en'=>"Edit", 'de'=>("Editieren")));
 * @param $p['fallbacklanguage'] optional language to use for undefined texts (useful for partially translated projects)
 * @param $p['forcelanguage'] optional language to use instead of user's preferred language
 * @param $p['global'] store text object in global it_text for global functions (default: true)
 * @param $p['phpfile'] optional texts file(s), default: all texts.php in include path
 * @param $p['phpfiles'] text files to load in addition to $p['phpfile'] (Note: $p['phpfile'] defaults to all texts.php files in include path)
 * @param $p['transmogrifiers'] comma separated functions that may be called by using {foo:bar} (foo will be called with bar as argument) in T()
 */
function __construct($p = array())
{
    if (!$p['phpfile'])
    {
        # Find all texts.php in path (abs path in case we need to save)
        foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $dir)
            if (file_exists($phpfile = "$dir/texts.php"))
                $p['phpfiles'][] = $phpfile;
    }

    $this->p = ($p += (array)$GLOBALS['it_text_defaultconfig'] + array(
        'global' => true,
        'phpfiles' => array_unique(array_merge((array)$p['phpfiles'], (array)$p['phpfile'])),
    ));
    $this->allowedfuncs = array_flip(explode(",", $p['transmogrifiers']));

    # Read and merge texts from php files if none defined yet
    foreach ($p['phpfiles'] as $phpfile)
    {
        $this->statictext += ($ret = include($phpfile));

        if ($GLOBALS['debug_texts'])
        {
            $service = strpos($phpfile, $GLOBALS['ULTRAHOME']) !== false ? '' : it::match('/www/([^/.]+)', $phpfile);
            $this->label_to_service += array_combine(array_keys($ret), array_fill(0, count($ret), $service));
        }
    }

    # Get array of supported languages and their names
    $this->languages_available = (array)$this->statictext['_'];
    foreach ($this->languages_available as $code => $languagename)
    {
        # Only use a language in browser detection below if it's not disabled by a leading '-'
        if (substr($languagename, 0, 1) != '-')
        {
            $this->languages[$code] = $languagename;
            if (!$this->actlanguage)
                $this->initlang($code); # failsafe lang
        }
    }

    # Set our default language according to browser preference
    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
    {
        foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $code)
            if ($this->initlang($code) || $this->initlang(substr($code, 0, 2))) # lang from browser/lang group from browser
                break;
    }
    $this->defaultlanguage = $this->actlanguage;

    $this->initlang(it::match('\.([a-z]{2})\.[^./]+$', $_SERVER['PHP_SELF'])); # lang from url override
    $this->initlang($p['forcelanguage']); # programmer override

    # Create empty array to activate sampling; dont kill any existing one
    if (it::is_devel() || rand(1, $_POST ? 10 : 100) == 1)
        $GLOBALS['it_text_sampling'] = (array)$GLOBALS['it_text_sampling'];

    # Make this object available under $GLOBALS['it_text'], or add my texts to $GLOBALS['it_text'] if it exists
    if ($p['global'])
    {
        if (!$GLOBALS['it_text'])
            $GLOBALS['it_text'] =& $this;
        else
            $GLOBALS['it_text']->statictext += $this->statictext;
    }
}