Improved SetLangauge

asharris
2010-10-12
2012-09-18
  • asharris
    asharris
    2010-10-12

    This small change allows the language directory to reside anywhere on the PHP
    Include path list:

    /**

    • Sets the language for all class error messages. Returns false
    • if it cannot load the language file. The default language type
    • is English.
    • @param string $lang_type Type of language (e.g. Portuguese: "br")
    • @param string $lang_path Path to the language file directory
    • @access public
    • @return bool
      */
      function SetLanguage($lang_type, $lang_path = "language/") {

    $pathArray = explode(PATH_SEPARATOR, get_include_path() );

    $bIncluded = false;

    foreach($pathArray as $incPath)

    {

    if(file_exists($incPath . "/" .
    $lang_path.'phpmailer.lang-'.$lang_type.'.php'))

    {

    include($lang_path.'phpmailer.lang-'.$lang_type.'.php');

    $bIncluded = true;

    }

    else if(file_exists($incPath . "/" . $lang_path.'phpmailer.lang-en.php'))

    {

    include($lang_path.'phpmailer.lang-en.php');

    $bIncluded = true;

    }

    }

    if(!$bIncluded)

    {

    $PHPMAILER_LANG = array();

    $PHPMAILER_LANG = 'You must provide at least one ' .

    $PHPMAILER_LANG = ' mailer is not supported.';

    $PHPMAILER_LANG = 'Could not execute: ';

    $PHPMAILER_LANG = 'Could not instantiate mail function.';

    $PHPMAILER_LANG = 'SMTP Error: Could not authenticate.';

    $PHPMAILER_LANG = 'The following From address failed: ';

    $PHPMAILER_LANG = 'SMTP Error: The following ' .

    $PHPMAILER_LANG = 'SMTP Error: Data not accepted.';

    $PHPMAILER_LANG = 'SMTP Error: Could not connect to SMTP host.';

    $PHPMAILER_LANG = 'Could not access file: ';

    $PHPMAILER_LANG = 'File Error: Could not open file: ';

    $PHPMAILER_LANG = 'Unknown encoding: ';

    $PHPMAILER_LANG = 'Signing Error: ';

    }

    $this->language = $PHPMAILER_LANG;

    return true;

    }