function execute(&$controller, &$request) { $from_charset = $_POST['charset']; $to_charset = $_POST['newcharset']; $lang = $_POST['language']; $textdomain = mamboCore::get('rootPath') . "/language"; $language = new mamboLanguage($lang); $language->load(); $language->charset = $to_charset; $language->save(); $gettext_admin = new PHPGettextAdmin(); foreach ($language->files as $arr) { $gettext_admin->convert_charset($arr['domain'], $textdomain, $lang, $from_charset, $to_charset); $gettext_admin->message_format($arr['domain'], $textdomain, $lang); } #return $controller->redirect('index', 'language'); $request->set('task', 'edit'); $request->set('act', 'language'); $request->set('lang', $lang); $controller->view('edit'); # /*$admin = new PHPGettextAdmin(); $admin->convert_encoding($catalog, $from, $to); dump(iconv_get_encoding());*/ }
function extract($domain, $scandirs, $language = 'untranslated') { $path = mamboCore::get('rootPath'); $textdomain = $path . '/language'; if (!file_exists("{$textdomain}/{$language}/{$domain}.pot")) { $catalog = new PHPGettext_Catalog($domain, $textdomain); $catalog->setproperty('mode', _MODE_POT_); $catalog->setproperty('lang', $language); $headers = $this->header(); $catalog->setproperty('comments', $headers[0]); $catalog->setproperty('headers', $headers[1]); $catalog->save(); } $this->scan_xml($domain, $textdomain, $scandirs, $language); $gettext_admin = new PHPGettextAdmin(); $cwd = getcwd(); chdir($path); $php_sources = array(); if (is_array($scandirs)) { foreach ($scandirs as $subdir) { $php_sources = array_merge($php_sources, $this->read_dir($subdir, 'php', true)); } } else { $php_sources = $this->read_dir($scandirs, 'php', true); } $gettext_admin->xgettext($domain, $textdomain, $php_sources, $language); chdir($cwd); return true; }
function execute(&$controller, &$request) { $lang = $request->get('lang'); $language = new mamboLanguage($lang); //$language->load(true); $domain = $_POST['domain']; $textdomain = mamboCore::get('rootPath') . "/language"; $gettext_admin = new PHPGettextAdmin(true); $gettext_admin->compile($lang, $textdomain, $language->charset); $language->save(); return $controller->redirect('index', 'catalogs'); }
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'); }
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(); } }