Pop\I18n\I18n::loadFile PHP Метод

loadFile() публичный Метод

Load language content from an XML file.
public loadFile ( string $langFile ) : void
$langFile string
Результат void
    public function loadFile($langFile)
    {
        if (file_exists($langFile)) {
            if (($xml = @new \SimpleXMLElement($langFile, LIBXML_NOWARNING, true)) !== false) {
                $key = 0;
                $length = count($xml->locale);
                // Find the locale node key
                for ($i = 0; $i < $length; $i++) {
                    if ($this->locale == (string) $xml->locale[$i]->attributes()->region) {
                        $key = $i;
                    }
                }
                // If the locale node matches the current locale
                if ($this->locale == (string) $xml->locale[$key]->attributes()->region) {
                    foreach ($xml->locale[$key]->text as $text) {
                        if (isset($text->source) && isset($text->output)) {
                            $this->content['source'][] = (string) $text->source;
                            $this->content['output'][] = (string) $text->output;
                        }
                    }
                }
            } else {
                throw new Exception('Error: There was an error processing that XML file.');
            }
        } else {
            throw new Exception('Error: The language file ' . $langFile . ' does not exist.');
        }
    }

Usage Example

 /**
  * Constructor method to instantiate the default controller object
  *
  * @param  Request  $request
  * @param  Response $response
  * @param  Project  $project
  * @param  string   $viewPath
  * @return self
  */
 public function __construct(Request $request = null, Response $response = null, Project $project = null, $viewPath = null)
 {
     if (null === $viewPath) {
         $cfg = $project->module('Phire')->asArray();
         $viewPath = __DIR__ . '/../../../../../view/phire/install';
         if (isset($cfg['view'])) {
             $class = get_class($this);
             if (is_array($cfg['view']) && isset($cfg['view'][$class])) {
                 $viewPath = $cfg['view'][$class];
             } else {
                 if (is_array($cfg['view']) && isset($cfg['view']['*'])) {
                     $viewPath = $cfg['view']['*'] . '/install';
                 } else {
                     if (is_string($cfg['view'])) {
                         $viewPath = $cfg['view'] . '/install';
                     }
                 }
             }
         }
     }
     $lang = isset($_GET['lang']) ? $_GET['lang'] : 'en_US';
     if (!defined('POP_LANG')) {
         define('POP_LANG', $lang);
     }
     $this->i18n = I18n::factory();
     $this->i18n->loadFile($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . '/vendor/Phire/data/assets/i18n/' . $this->i18n->getLanguage() . '.xml');
     parent::__construct($request, $response, $project, $viewPath);
     $this->sess = Session::getInstance();
 }
All Usage Examples Of Pop\I18n\I18n::loadFile