_options = array_merge($this->_options, $config->toArray()); parent::__construct($options); } protected function _loadTranslationData($filename, $locale, array $options = array()) { $this->_fileName = $filename; return parent::_loadTranslationData($filename, $locale, $options); } public function translate($messageId, $locale = null) { $this->_translated = true; if (null === $messageId) { return null; } $result = parent::translate($messageId, $locale); if (is_string($messageId) && is_array($result)) { return reset($result); } if (!$this->_translated && ($section = $this->getSection()) && $section !== Qs_Translate::SECTION_COMMON) { $result = Qs_Translate::translate($messageId, Qs_Translate::SECTION_COMMON); } return $result; } protected function isNeedTranslation($text) { if (false !== strpos($text, 'Lorem')) { return false; } if (preg_match('/[\d]+/', $text)) { return false; } if (mb_strlen($text) < 3) { return false; } return true; } protected function _log($message, $locale) { $this->_translated = false; if ($locale !== 'en' && !$this->isNeedTranslation($message)) { return $this; } if ($this->_options['logUntranslated']) { $message = str_replace( ['%message%', '%locale%', '%filename%'], [$message, $locale, $this->_fileName], $this->_options['logMessage'] ); if (constant('DEBUG')) { Qs_Debug::log('Untranslated: ' . $message); } if ($this->_options['log']) { $this->_options['log']->log($message, $this->_options['logPriority']); } else { trigger_error($message, E_USER_NOTICE); } } if (empty($this->_options['appendUntranslated']) || $locale === DEFAULT_LANGUAGE) { return $this; } $message = trim($message); if (!$message) { return $this; } $info = pathinfo($this->_fileName); $poFile = dirname($info['dirname']) . '/' . $locale . '/' . $info['filename'] . '.po'; $messages = Qs_Gettext_PoFile::load($poFile); $messages[$message] = $message; Qs_Gettext_PoFile::save($poFile, $messages); return $this; } public function getSection() { return $this->_section; } public function setSection($section) { $this->_section = $section; return $this; } }