/**
  * Edit the language items of a module
  *
  * Left Side => Right Side
  * English   => Target Language
  *
  */
 public function action_admin_edit()
 {
     if ($this->request->getRequestMethod() == 'GET') {
         // get "module" and target "locale" for editing
         $module = $this->request->getParameter('module', 'GET');
         $locale = $this->request->getParameter('locale', 'GET');
         // transform "de-DE" to "de_DE" because locale dirs have underscores
         $locale = str_replace('-', '_', $locale);
         /**
          * We translate *from* english to the target language.
          *
          * English locale is the base for all translations.
          * This fetches all english language strings of the module.
          */
         include ROOT_FRAMEWORK . 'gettext/po.gettext.php';
         $english_data = Gettext_PO_File::read($this->getModulePOFilename($module, 'en_GB'));
         $english_data = $this->preparePODataForView($english_data);
         #Clansuite_Debug::printR($english_data);
         $this->getView()->assign('english_locale', $english_data);
         /**
          * We translate *to* the target locale.
          *
          * The fetches the locale to edit.
          */
         $target_locale_pofile = $this->getModulePOFilename($module, $locale);
         $target_locale_data = Gettext_PO_File::read($target_locale_pofile);
         $target_locale_data = $this->preparePODataForView($target_locale_data);
         #Clansuite_Debug::printR($target_locale_data);
         $this->view->assign('target_locale', $target_locale_data);
         /**
          * Setup Form
          *
          * This form shows one text field per language string (gettext msgstr).
          * The english original string is displayed as formelement description text.
          *
          * Developer Note:
          * ---------------
          * If anyone wants to polish this with an implementation of a table view
          * with ajax live-editing or inline-editing of table cells, then
          * (a) you will make me happy and (b) if you contact me before
          * and discuss the implementation details, then i will pay for it.
          * Take the folling table as an good example for an gettext editor dialog:
          * http://www.gted.org/screenshots/entries_horizontal.gif
          *
          */
         $form = new Clansuite_Form('Edit Locale');
         $form->setLegend('Edit Locale');
         $form->setHeading('You are editing the "' . $locale . '" locale of the module "' . ucfirst($module) . '".');
         // remove metadata from end of array
         array_pop($english_data);
         $i = 0;
         foreach ($english_data as $data_set) {
             $msgid = htmlentities($data_set['msgid']);
             $form->addElement('text')->setName('locale_form[' . $msgid . ']')->setLabel('Phrase ' . $i)->setDescription('"' . $msgid . '"');
             $i = $i + 1;
         }
         // add hidden formfields to transfers our target locale and module
         $form->addElement('hidden')->setName('locale')->setValue($locale);
         $form->addElement('hidden')->setName('module')->setValue($module);
         $form->addElement('buttonbar');
         $this->view->assign('form', $form->render());
         $this->display();
     }
     // update
     if ($this->request->getRequestMethod() == 'POST') {
         $this->action_admin_update();
     }
 }
Exemple #2
0
 public function testGetHeading()
 {
     $this->form->setHeading('heading2');
     // via getter - returns string
     $this->assertEqual('heading2', $this->form->getHeading());
 }