[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/administrator/components/com_languages/actions/ -> auto_translate.action.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Languages
   5  * @author Mambo Foundation Inc see README.php
   6  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   7  * See COPYRIGHT.php for copyright notices and details.
   8  * @license GNU/GPL Version 2, see LICENSE.php
   9  *
  10  * Redistributions of files must retain the above copyright notice.
  11  *
  12  * Mambo is free software; you can redistribute it and/or
  13  * modify it under the terms of the GNU General Public License
  14  * as published by the Free Software Foundation; version 2 of the License.
  15  */
  16  
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  class auto_translateAction extends Action
  19  {
  20      function execute(&$controller, &$request)
  21      {
  22          #FIXME
  23          $domain     = mosGetParam($_POST,'domain');
  24          $textdomain = mosGetParam($_POST,'textdomain');
  25          $lang       = mosGetParam($_POST,'lang');
  26          $comments   = mosGetParam($_POST,'comments');
  27          $headers    = mosGetParam($_POST,'headers');
  28          
  29          $language = new mamboLanguage($lang, $textdomain);
  30          $catalog = new PHPGettext_catalog($domain, $textdomain);
  31          $catalog->setproperty('mode', 'po');
  32          $catalog->setproperty('lang', $lang);
  33          $catalog->load();
  34  
  35          $catalog->setComments($comments);
  36          $catalog->setHeaders($headers);        
  37  
  38          foreach ($_POST as $key => $value) {
  39              if (preg_match('/^([a-z]+)[_]?([0-9]+)?_([0-9]+)$/', $key, $matches))  {
  40                  switch ($matches[1])
  41                  {
  42                      case 'msgid':
  43                      $messages[$matches[3]]['msgid'] = $value;
  44                      break;
  45                      case 'msgid_plural':
  46                      $messages[$matches[3]]['msgid_plural'] = $value;
  47                      break;
  48                      case 'msgstr':
  49                      if ($matches[2] != '') {
  50                          $messages[$matches[3]]['msgstr'][$matches[2]] =  stripslashes($value);
  51                      } else {
  52                          $messages[$matches[3]]['msgstr'] =  stripslashes($value);
  53                      }
  54                      break;
  55                      case 'fuzzy':
  56                      $messages[$matches[3]]['fuzzy'] = $value == 'true' ? true : false;
  57                      break;
  58                  }
  59              }
  60          }
  61          foreach ($messages as $index => $arr) {
  62              if (strcmp($catalog->strings[$index]->msgid, $arr['msgid']) == 0) {
  63                  $catalog->strings[$index]->setmsgstr($arr['msgstr']);
  64                  if ($arr['fuzzy']) {
  65                      $catalog->strings[$index]->setfuzzy($arr['fuzzy']);
  66                  }
  67              }
  68          }
  69          $catalog->save();
  70  
  71          $configuration =& mamboCore::getMamboCore();
  72          $gettext_admin = new PHPGettextAdmin($configuration->get('mosConfig_locale_use_gettext'));
  73          $gettext_admin->update_translation($domain, $textdomain, $lang);
  74  
  75          if ($request->get('act') == 'catalogs') {
  76              $request->set('domain', $domain);
  77          }
  78          $controller->view('edit');
  79      }
  80  }
  81  
  82  ?>