Esempio n. 1
0
 function editcatalog(&$renderer, &$request)
 {
     $lang = $request->get('lang');
     $language = new mamboLanguage($lang);
     $domain = $request->get('domain');
     $catalog = new PHPGettext_catalog($domain, mamboCore::get('rootPath') . "/language");
     $catalog->setproperty('mode', _MODE_PO_);
     $catalog->setproperty('lang', $lang);
     $catalog->load();
     $nplurals = 2;
     $_VERSION = new version();
     if (strpos($catalog->headers['Last-Translator'], 'FULL NAME')) {
         $catalog->headers['Last-Translator'] = "Translation <*****@*****.**>";
     }
     if (strpos($catalog->headers['Language-Team'], 'LANGUAGE')) {
         $catalog->headers['Language-Team'] = "Translation <*****@*****.**>";
     }
     $catalog->headers['Project-Id-Version'] = $_VERSION->PRODUCT . ' ' . $_VERSION->RELEASE;
     $catalog->headers['Report-Msgid-Bugs-To'] = '*****@*****.**';
     $catalog->headers['Plural-Forms'] = $language->plural_form['expression'];
     $catalog->headers['Content-Type'] = 'text/plain; charset=' . $language->charset;
     $renderer->addvar('header', sprintf(T_('Translate Catalog: %s [%s]'), $domain, $lang));
     $renderer->addvar('nplurals', $language->plural_form['nplurals']);
     $renderer->addbyref('catalog', $catalog);
     $renderer->addvar('domain', $domain);
     $renderer->addvar('content', $renderer->fetch('editcatalog.tpl.php'));
 }
Esempio n. 2
0
 function execute(&$controller, &$request)
 {
     $domain = $_POST['domain'];
     $textdomain = $_POST['textdomain'];
     $lang = $_POST['lang'];
     $catalog = new PHPGettext_catalog($domain, $textdomain);
     $catalog->setproperty('mode', 'po');
     $catalog->setproperty('lang', $lang);
     $catalog->load();
     $catalog->setComments($_POST['comments']);
     $catalog->setHeaders($_POST['headers']);
     $plural_forms = $catalog->headers['Plural-Forms'];
     preg_match('/nplurals[\\s]*[=]{1}[\\s]*([\\d]+);[\\s]*plural[\\s]*[=]{1}[\\s]*(.*);/', $plural_forms, $matches);
     $is_plural = $matches[1] > 1;
     foreach ($_POST as $key => $value) {
         //          if (preg_match('/^([a-z]+)[_]?([0-9]+)?_([0-9]+)$/', $key, $matches))  {
         if (preg_match('/^([a-z]+[_]?[a-z]+?)[_]?([0-9]+)?_([0-9]+)$/', $key, $matches)) {
             switch ($matches[1]) {
                 case 'msgid':
                     $messages[$matches[3]]['msgid'] = $value;
                     break;
                 case 'msgid_plural':
                     if ($is_plural) {
                         $messages[$matches[3]]['msgid_plural'] = $value;
                     }
                     break;
                 case 'msgstr':
                     if (!empty($messages[$matches[3]]['msgid_plural'])) {
                         if ($matches[2] != '') {
                             $messages[$matches[3]]['msgstr'][$matches[2]] = stripslashes($value);
                         } else {
                             $messages[$matches[3]]['msgstr'][0] = stripslashes($value);
                             $messages[$matches[3]]['msgstr'][1] = '';
                         }
                     } else {
                         $messages[$matches[3]]['msgstr'] = stripslashes($value);
                     }
                     break;
                 case 'fuzzy':
                     $messages[$matches[3]]['fuzzy'] = $value == 'true' ? true : false;
                     break;
             }
         }
     }
     foreach ($messages as $index => $arr) {
         if (strcmp($catalog->strings[$index]->msgid, $arr['msgid']) == 0) {
             $catalog->strings[$index]->setmsgstr($arr['msgstr']);
             $catalog->strings[$index]->msgid_plural = isset($arr['msgid_plural']) ? $arr['msgid_plural'] : null;
             $catalog->strings[$index]->setfuzzy($arr['fuzzy']);
         }
     }
     $catalog->save();
     if ($request->get('act') == 'catalogs') {
         $request->set('domain', $domain);
     }
     $controller->view('edit');
 }
Esempio n. 3
0
 function execute(&$controller, &$request)
 {
     #FIXME
     $domain = $_POST['domain'];
     $textdomain = $_POST['textdomain'];
     $lang = $_POST['lang'];
     $language = new mamboLanguage($lang, $textdomain);
     $catalog = new PHPGettext_catalog($domain, $textdomain);
     $catalog->setproperty('mode', 'po');
     $catalog->setproperty('lang', $lang);
     $catalog->load();
     $catalog->setComments($_POST['comments']);
     $catalog->setHeaders($_POST['headers']);
     foreach ($_POST as $key => $value) {
         if (preg_match('/^([a-z]+)[_]?([0-9]+)?_([0-9]+)$/', $key, $matches)) {
             switch ($matches[1]) {
                 case 'msgid':
                     $messages[$matches[3]]['msgid'] = $value;
                     break;
                 case 'msgid_plural':
                     $messages[$matches[3]]['msgid_plural'] = $value;
                     break;
                 case 'msgstr':
                     if ($matches[2] != '') {
                         $messages[$matches[3]]['msgstr'][$matches[2]] = stripslashes($value);
                     } else {
                         $messages[$matches[3]]['msgstr'] = stripslashes($value);
                     }
                     break;
                 case 'fuzzy':
                     $messages[$matches[3]]['fuzzy'] = $value == 'true' ? true : false;
                     break;
             }
         }
     }
     foreach ($messages as $index => $arr) {
         if (strcmp($catalog->strings[$index]->msgid, $arr['msgid']) == 0) {
             $catalog->strings[$index]->setmsgstr($arr['msgstr']);
             if ($arr['fuzzy']) {
                 $catalog->strings[$index]->setfuzzy($arr['fuzzy']);
             }
         }
     }
     $catalog->save();
     $gettext_admin = new PHPGettextAdmin();
     $gettext_admin->update_translation($domain, $textdomain, $lang);
     if ($request->get('act') == 'catalogs') {
         $request->set('domain', $domain);
     }
     $controller->view('edit');
 }
Esempio n. 4
0
 function updatecatalog($compile = true, $add_to_dict = true)
 {
     $domain = $_POST['domain'];
     $textdomain = $_POST['textdomain'];
     $lang = $_POST['lang'];
     $catalog = new PHPGettext_catalog($domain, $textdomain);
     $catalog->setproperty('mode', 'po');
     $catalog->setproperty('lang', $lang);
     $catalog->load();
     $catalog->setComments($_POST['comments']);
     $catalog->setHeaders($_POST['headers']);
     $plural_forms = $catalog->headers['Plural-Forms'];
     preg_match('/nplurals[\\s]*[=]{1}[\\s]*([\\d]+);[\\s]*plural[\\s]*[=]{1}[\\s]*(.*);/', $plural_forms, $matches);
     $is_plural = $matches[1] > 1;
     foreach ($_POST as $key => $value) {
         if (preg_match('/^([a-z]+[_]?[a-z]+?)[_]?([0-9]+)?_([0-9]+)$/', $key, $matches)) {
             switch ($matches[1]) {
                 case 'msgid':
                     if (get_magic_quotes_gpc() == 1) {
                         $value = stripslashes($value);
                         //$value = htmlentities($value);
                     }
                     $messages[$matches[3]]['msgid'] = $value;
                     break;
                 case 'msgid_plural':
                     if ($is_plural) {
                         $messages[$matches[3]]['msgid_plural'] = $value;
                     }
                     break;
                 case 'msgstr':
                     if (!empty($messages[$matches[3]]['msgid_plural'])) {
                         if ($matches[2] != '') {
                             $messages[$matches[3]]['msgstr'][$matches[2]] = stripslashes($value);
                         } else {
                             $messages[$matches[3]]['msgstr'][0] = stripslashes($value);
                             $messages[$matches[3]]['msgstr'][1] = '';
                         }
                     } else {
                         $messages[$matches[3]]['msgstr'] = stripslashes($value);
                     }
                     break;
                 case 'fuzzy':
                     $messages[$matches[3]]['fuzzy'] = $value == 'true' ? true : false;
                     break;
             }
         }
     }
     foreach ($messages as $index => $arr) {
         if (strcmp($catalog->strings[$index]->msgid, $arr['msgid']) == 0) {
             $catalog->strings[$index]->setmsgstr($arr['msgstr']);
             $catalog->strings[$index]->msgid_plural = isset($arr['msgid_plural']) ? $arr['msgid_plural'] : null;
             $catalog->strings[$index]->setfuzzy($arr['fuzzy']);
         }
     }
     $catalog->save();
     $language = new mamboLanguage($lang);
     $language->save();
     $gettext_admin = new PHPGettextAdmin();
     $gettext_admin->add_to_dict($domain, $textdomain, $lang, $language->charset);
     $catalog->load();
     if ($compile) {
         $catalog->setproperty('mode', 'mo');
         $catalog->save();
     }
 }
Esempio n. 5
0
 function extract()
 {
     require_once dirname(__FILE__) . '/phpgettext.catalog.php';
     $gettext =& phpgettext();
     $path = _site_path_;
     $args = "--keyword=T_ --default-domain=phpgettext ";
     $args .= '-o ' . $path . 'locale/phpgettext.pot ';
     $args .= $path . 'includes/*.php ' . $path . 'templates/*.php';
     $gettext->xgettext($args);
     $catalog = new PHPGettext_catalog('phpgettext', $path . 'locale/');
     $catalog->setproperty('mode', _MODE_POT_);
     $catalog->load();
     $renderer =& renderer();
     $renderer->addbyref('catalog', $catalog);
     $renderer->addvar('mode', 'pot');
     $renderer->addvar('comments', $catalog->comments);
     $renderer->addvar('headers', $catalog->headers);
     $renderer->addvar('strings', $catalog->strings);
     return $this->view->view();
 }
Esempio n. 6
0
 /**
  * Enter description here...
  *
  * @param unknown_type $domain
  * @param unknown_type $langdir
  */
 function convert_charset($domain, $textdomain, $lang, $from_charset, $to_charset)
 {
     $path = "{$textdomain}/{$lang}";
     if ($this->has_gettext) {
         $cmd = $this->escCommand("msgconv") . " --to-code={$to_charset} -o " . $this->escPath("{$path}/{$domain}.po") . " " . $this->escPath("{$path}/{$domain}.po");
         $ret = $this->execute($cmd);
         return $ret;
     }
     if (!class_exists('ConvertCharset')) {
         return false;
     }
     $catalog = new PHPGettext_catalog($domain, $textdomain);
     $catalog->setproperty('mode', _MODE_PO_);
     $catalog->setproperty('lang', $lang);
     $catalog->load();
     $catalog->headers['Content-Type'] = "text/plain; charset={$to_charset}\n";
     $NewEncoding = new ConvertCharset();
     foreach ($catalog->strings as $index => $message) {
         if (empty($message->msgid_plural)) {
             $catalog->strings[$index]->msgstr = $NewEncoding->Convert($message->msgstr, $from_charset, $to_charset, false);
         }
     }
     $catalog->save();
     return true;
 }