Back to Language class

Method __construct

public
__construct
(mixed $lang = null, mixed $debug = false)
Constructor activating the default information of the language.
Parameters
  • string $lang The language
  • bool $debug Indicates if language debugging is enabled.
Since
  • 1.7.0
Class: Language
Project: Joomla

Method __construct - Source code

/**
 * Constructor activating the default information of the language.
 *
 * @param   string   $lang   The language
 * @param   boolean  $debug  Indicates if language debugging is enabled.
 *
 * @since   1.7.0
 */
public function __construct($lang = null, $debug = false)
{
    $this->strings = array();
    if ($lang == null) {
        $lang = $this->default;
    }
    $this->lang = $lang;
    $this->metadata = LanguageHelper::getMetadata($this->lang);
    $this->setDebug($debug);
    /*
     * Let's load the default override once, so we can profit from that, too
     * But make sure, that we don't enforce it on each language file load.
     * So don't put it in $this->override
     */
    if (!$this->debug && $lang !== $this->default) {
        $this->loadLanguage(JPATH_BASE . '/language/overrides/' . $this->default . '.override.ini');
    }
    $this->override = $this->parse(JPATH_BASE . '/language/overrides/' . $lang . '.override.ini');
    // Look for a language specific localise class
    $class = str_replace('-', '_', $lang . 'Localise');
    $paths = array();
    if (\defined('JPATH_SITE')) {
        // Note: Manual indexing to enforce load order.
        $paths[0] = JPATH_SITE . "/language/overrides/{$lang}.localise.php";
        $paths[2] = JPATH_SITE . "/language/{$lang}/localise.php";
        $paths[4] = JPATH_SITE . "/language/{$lang}/{$lang}.localise.php";
    }
    if (\defined('JPATH_ADMINISTRATOR')) {
        // Note: Manual indexing to enforce load order.
        $paths[1] = JPATH_ADMINISTRATOR . "/language/overrides/{$lang}.localise.php";
        $paths[3] = JPATH_ADMINISTRATOR . "/language/{$lang}/localise.php";
        $paths[5] = JPATH_ADMINISTRATOR . "/language/{$lang}/{$lang}.localise.php";
    }
    ksort($paths);
    $path = reset($paths);
    while (!class_exists($class) && $path) {
        if (is_file($path)) {
            require_once $path;
        }
        $path = next($paths);
    }
    if (class_exists($class)) {
        /**
         * Class exists. Try to find
         * -a transliterate method,
         * -a getPluralSuffixes method,
         * -a getIgnoredSearchWords method
         * -a getLowerLimitSearchWord method
         * -a getUpperLimitSearchWord method
         * -a getSearchDisplayCharactersNumber method
         */
        if (method_exists($class, 'transliterate')) {
            $this->transliterator = array($class, 'transliterate');
        }
        if (method_exists($class, 'getPluralSuffixes')) {
            $this->pluralSuffixesCallback = array($class, 'getPluralSuffixes');
        }
        if (method_exists($class, 'getIgnoredSearchWords')) {
            $this->ignoredSearchWordsCallback = array($class, 'getIgnoredSearchWords');
        }
        if (method_exists($class, 'getLowerLimitSearchWord')) {
            $this->lowerLimitSearchWordCallback = array($class, 'getLowerLimitSearchWord');
        }
        if (method_exists($class, 'getUpperLimitSearchWord')) {
            $this->upperLimitSearchWordCallback = array($class, 'getUpperLimitSearchWord');
        }
        if (method_exists($class, 'getSearchDisplayedCharactersNumber')) {
            $this->searchDisplayedCharactersNumberCallback = array($class, 'getSearchDisplayedCharactersNumber');
        }
    }
    $this->load();
}