예제 #1
0
 /**
  * get instance of translation adapter
  *
  * @param string $type
  * @param array $options
  * @return JalangHelperTranslator
  * 
  * @see JalangHelperTranslator
  */
 public static function getInstance($type, $options = array())
 {
     /*if(!isset($options['from']) || !isset($options['to'])) {
     			JError::raiseWarning(400, 'JalangHelperTranslator::getInstance() '.JText::_('MISSING_PARAMS_PASSED'));
     			return false;
     		}*/
     if (isset(self::$instance[$type]) && is_object(self::$instance[$type])) {
         return self::$instance[$type];
     } else {
         $translator = new JalangHelperTranslator();
         /**
          * @todo report Joomla to below issue
          * must setAdapter first since, getAdapter with options params passed will return incorrect object
          * 
          * Expected code for instead: $translator->getAdapter($type, $options);
          */
         $adapter = null;
         $translator->setAdapter($type, $adapter, $options);
         self::$instance[$type] = $translator->getAdapter($type);
     }
     return self::$instance[$type];
 }
예제 #2
0
 public function __construct($parent, $db, $options = array())
 {
     //$this->contentType = 'text/html';//text/plain
     parent::__construct();
 }
예제 #3
0
 /**
  * Method to get a list of articles.
  * Overridden to add a check for access levels.
  *
  * @return  mixed  An array of data items on success, false on failure.
  * @since   1.6.1
  */
 public function getItems()
 {
     $items = parent::getItems();
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $adapter = JalangHelper::getHelperContent();
     $translator = new JalangHelperTranslator();
     $params = JComponentHelper::getParams('com_jalang');
     $language = $app->getUserState('com_jalang.mainlanguage', '*');
     $languages = JHtml::_('contentlanguage.existing', true, true);
     if ($adapter->table_type == 'table') {
         if (!$language || $language == '*') {
             $language = JalangHelper::getDefaultLanguage();
         }
         $translator->fromLangTag = $language;
         $from_table = $translator->getLangTable('#__' . $adapter->table, $language);
         $filterById = $db->quoteName('st') . '.' . $db->quoteName($adapter->primarykey) . '=%d';
     } else {
         $translator->fromLangTag = $language;
         $from_table = '#__' . $adapter->table;
         $filterById = $db->quoteName('c') . '.' . $db->quoteName($adapter->primarykey) . '=%d';
         $translator->loadAssociate($adapter->table, $adapter->primarykey, $adapter->associate_context, false);
     }
     for ($x = 0, $count = count($items); $x < $count; $x++) {
         $sourceid = $items[$x]->{$adapter->primarykey};
         if ($adapter->table_type == 'table') {
             foreach ($languages as $cl) {
                 if ($cl->value != $language) {
                     $translator->toLangTag = $cl->value;
                     $translator->loadAssociate($adapter->table, $adapter->primarykey, $adapter->associate_context, true, array(sprintf($filterById, $sourceid)));
                 }
             }
         }
         $items[$x]->associations = isset($translator->aAssociation[$adapter->table][$sourceid]) ? $translator->aAssociation[$adapter->table][$sourceid] : array();
     }
     return $items;
 }
예제 #4
0
 public function __construct($parent, $db, $options = array())
 {
     //$this->contentType = 'text/html';//text/plain
     parent::__construct();
     $this->_apiKey = $this->params->get('google_browser_api_key', '');
 }
예제 #5
0
 public function translateAll()
 {
     $this->consoleInit();
     $input = JFactory::getApplication()->input;
     //$from = $input->get('translate_from', '*');
     //$to = $input->get('translate_to', '*');
     $languages = JalangHelper::getListInstalledLanguages();
     $from = JalangHelper::getDefaultLanguage();
     if (!headers_sent()) {
         header('Content-type: text/html; charset=utf-8');
     }
     foreach ($languages as $lang) {
         if ($lang->element == $from) {
             continue;
         }
         $params = JComponentHelper::getParams('com_jalang');
         $translator = JalangHelperTranslator::getInstance($params->get('translator_api_active', 'bing'));
         $translator->sendOutput('<h3>' . JText::sprintf('START_TO_TRANSLATE_FOR_THE_VAR_LANGUAGE', $lang->name) . '</h3>');
         $translator->translateAllTables($from, $lang->element);
         //sleep(2);
         $translator->sendOutput(str_pad('', 50, '-'));
     }
     jexit('Done');
 }
예제 #6
0
 /**
  * Build an SQL query to load the list data.
  *
  * @return  JDatabaseQuery
  * @since   1.6
  */
 public function getListQuery2($model)
 {
     if (!$this->table) {
         $this->errorExtendMethod(__METHOD__);
         return false;
     }
     // Create a new query object.
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('*');
     $query->from('#__' . $this->table . ' AS a');
     // Filter on the language.
     $defaultLanguage = JalangHelper::getDefaultLanguage();
     $language = $model->getState('mainlanguage');
     $filter_search = $model->getState('filter.search');
     if ($language) {
         if ($this->table_type == 'native' || $this->table_type == 'table_ml') {
             $langField = 'a.' . $db->quoteName($this->language_field);
             if ($this->language_mode == 'id') {
                 $query->where($langField . ' = ' . $db->quote(JalangHelper::getLanguageIdFromCode($language)));
             } else {
                 if ($language == $defaultLanguage) {
                     $query->where('(' . $langField . ' = ' . $db->quote($language) . ' OR ' . $langField . ' = ' . $db->quote('*') . ' OR ' . $langField . ' = ' . $db->quote('') . ')');
                 } else {
                     $query->where($langField . ' = ' . $db->quote($language));
                 }
             }
         } elseif ($this->table_type == 'table') {
             if ($language == '*') {
                 $language = $defaultLanguage;
             }
             $params = JComponentHelper::getParams('com_jalang');
             $translator = JalangHelperTranslator::getInstance($params->get('translator_api_active', 'bing'));
             $table = $translator->getLangTable($this->table, $language);
             $query->clear('from');
             $query->from('#__' . $table);
         } elseif ($this->table_type == 'alias') {
             if ($language != '*') {
                 @(list($shortlang, $country) = explode('-', $language));
                 if ($language == $defaultLanguage) {
                     $query->where('(' . $db->quoteName($this->alias_field) . ' LIKE ' . $db->quote('%-' . $shortlang) . ' OR ' . $db->quoteName($this->alias_field) . ' NOT REGEXP ' . $db->quote('\\-[a-z]{2}$') . ')');
                 } else {
                     $query->where($db->quoteName($this->alias_field) . ' LIKE ' . $db->quote('%-' . $shortlang));
                 }
             } else {
                 $query->where($db->quoteName($this->alias_field) . ' NOT REGEXP ' . $db->quote('\\-[a-z]{2}$'));
             }
         }
     }
     if (count($this->translate_filters)) {
         $query->where($this->translate_filters);
     }
     if ($filter_search) {
         $fields = $this->getDisplayFields();
         if (is_array($fields)) {
             $filterKeyword = array();
             foreach ($fields as $field => $ftitle) {
                 $filterKeyword[] = $db->quoteName($field) . ' LIKE ' . $db->quote('%' . $filter_search . '%');
             }
             $query->where('(' . implode(' OR ', $filterKeyword) . ')');
         } else {
             $query->where($db->quoteName($this->title_field) . ' LIKE ' . $db->quote('%' . $filter_search . '%'));
         }
     }
     $ordering = $model->getState('list.ordering', 'a.ordering');
     if (in_array($ordering, $this->getSortFields())) {
         $query->order($ordering . ' ' . $model->getState('list.direction', 'ASC'));
     }
     return $query;
 }