Example #1
0
 /**
  * An editor view for the fuel lang entries
  */
 public function post_terms()
 {
     $terms = \Input::post('terms', array());
     try {
         foreach ($terms as $lang => $phrases) {
             \Lang::save('common.db', $phrases, $lang);
         }
     } catch (\Exception $e) {
         // Nothing
     }
     \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => \Lang::get('admin.messages.translations_save_success')));
     $referrer = \Input::referrer('/admin');
     return \Response::redirect($referrer);
 }
 function createComponent($name)
 {
     switch ($name) {
         case 'translateTabella':
             $datasource = Lang::getDatasourceGroupByKey();
             $grid = new Tabella($datasource, array('sorting' => 'desc', 'order' => 'key', "onSubmit" => function ($post) {
                 Lang::save(@$post['key'], @$post);
                 Lang::invalidateCache();
             }));
             $grid->addColumn("Klúč", "key", array("width" => 50, 'editable' => true));
             foreach (Lang::getAll() as $l) {
                 $grid->addColumn($l['iso'], $l['iso'], array("width" => 50, 'editable' => true));
             }
             $this->addComponent($grid, $name);
             break;
         default:
             return parent::createComponent($name);
             break;
     }
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCategory !== null) {
             if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
                 $affectedRows += $this->aCategory->save($con);
             }
             $this->setCategory($this->aCategory);
         }
         if ($this->aLang !== null) {
             if ($this->aLang->isModified() || $this->aLang->isNew()) {
                 $affectedRows += $this->aLang->save($con);
             }
             $this->setLang($this->aLang);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Auto translate common terms
  */
 public function onSaveTerms($file, $lang, $language)
 {
     // Try and find child languages
     $childLanguages = \CMF\Model\Language::select('item')->where('update_from IS NOT NULL')->andWhere('update_from.code = :code')->andWhere('item.visible = true')->leftJoin('item.update_from', 'update_from')->setParameter('code', $language)->getQuery()->getResult();
     // Run if child languages are found
     if (!count($childLanguages)) {
         return;
     }
     foreach ($childLanguages as $childLanguage) {
         // Translate the terms for each language
         $terms = $this->translateArray($lang, $language, $childLanguage->code);
         if (is_array($terms)) {
             try {
                 \Lang::save($file, $terms, $childLanguage->code);
             } catch (\Exception $e) {
             }
         }
     }
 }
Example #5
0
 /**
  * Register new language
  *
  * @param sting $lang vi|en|...
  *
  * @access public
  * @author Dao Anh Minh
  */
 public function action_edit($lang = '')
 {
     $lang_path = APPPATH . "lang/{$lang}";
     if (is_null($lang) or !is_dir($lang_path)) {
         Session::set_flash('error', 'Ngôn ngữ không tồn tại');
         Response::redirect('admin/language');
     }
     $view = View::forge('admin/language/edit');
     $view->data = array('shortname' => $lang, 'new_langs' => Lang::load('language.php', null, $lang), 'default_langs' => Lang::load('language.php', null, 'vi'));
     $view->err = array();
     // validate input data
     $val = Validation::forge();
     // Prepare data to display in view and validate
     foreach ($view->data['default_langs'] as $parent_key => $langs) {
         foreach (array_keys($langs) as $lang_key) {
             // Add field to validate
             $val->add_field("{$parent_key}.{$lang_key}", 'Nội dung', 'required');
         }
     }
     if (Input::method() == 'POST') {
         if ($val->run(Input::post('langs'))) {
             Lang::save('language.php', Input::post('langs'), $lang);
             Session::set_flash('success', 'Chỉnh sửa thành công');
             Response::redirect('admin/language');
         } else {
             Session::set_flash('error', 'Có lỗi nhập liệu');
             $view->data['shortname'] = $lang;
             $view->data['new_langs'] = Input::post('langs');
             $view->err = $val->error_message();
         }
     }
     $this->template->title = 'Chỉnh sửa ngôn ngữ';
     $this->template->content = $view;
 }