|
CVS: phpwiki/lib/plugin _WikiTranslation.php,1.14,1.15: msg#00133web.wiki.phpwiki.checkins
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7775/lib/plugin Modified Files: _WikiTranslation.php Log Message: add fast_translate: setlocale() switching with the gettext extension is by far too slow; add default pagelist args Index: _WikiTranslation.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/_WikiTranslation.php,v retrieving revision 1.14 retrieving revision 1.15 diff -u -2 -b -p -d -r1.14 -r1.15 --- _WikiTranslation.php 8 Jul 2004 20:30:07 -0000 1.14 +++ _WikiTranslation.php 25 Jan 2005 08:06:47 -0000 1.15 @@ -2,5 +2,5 @@ rcs_id('$Id$'); /* - Copyright 2004 $ThePhpWikiProgrammingTeam + Copyright 2004,2005 $ThePhpWikiProgrammingTeam This file is part of PhpWiki. @@ -92,7 +92,17 @@ $pgsrc_container = _("PhpWikiAdministration/Rename") .','. _("PhpWikiAdministration/Replace") .','. + _("PhpWikiAdministration/SetAcl") .','. _("PhpWikiDocumentation") .','. _("PhpWikiPoll") .','. _("PloticusPlugin") .','. + _("PgrsrcTranslation") .','. + _("PgrsrcTranslation/de") .','. + _("PgrsrcTranslation/fr") .','. + _("PgrsrcTranslation/it") .','. + _("PgrsrcTranslation/es") .','. + _("PgrsrcTranslation/nl") .','. + _("PgrsrcTranslation/sv") .','. + _("PgrsrcTranslation/ja") .','. + _("PgrsrcTranslation/zh") .','. _("RawHtmlPlugin") .','. _("RecentVisitors") .','. @@ -100,4 +110,5 @@ $pgsrc_container = _("ReleaseNotes") .','. _("RichTablePlugin") .','. +// _("SpellCheck") .','. _("SteveWainstead") .','. _("SystemInfoPlugin") .','. @@ -132,5 +143,7 @@ extends WikiPlugin function getDefaultArguments() { - return + return array_merge + ( + PageList::supportedArgs(), array( 'languages' => '', // comma delimited string of de,en,sv,... 'string' => '', @@ -141,11 +154,13 @@ extends WikiPlugin 'from_lang' => false, 'include_empty' => false, - 'exclude' => '', - 'sortby' => '', - 'limit' => 0, - 'nolinks' => false, // don't display any links (for development only) - 'noT' => false, // don't display the T link (for development only) + //'exclude' => '', + //'sortby' => '', + //'limit' => 0, + 'nolinks' => false, // don't display any links + // (for development only) + 'noT' => false, // don't display the T link + // (for development only) 'debug' => false - ); + )); } @@ -154,5 +169,6 @@ extends WikiPlugin update_locale($lang); if ($lang == 'en') { - //hack alert! we need hash for stepping through it, even if it's in the wrong language + // Hack alert! we need hash for stepping through it, even if it's + // in the wrong language include (FindFile("locale/de/LC_MESSAGES/phpwiki.php", 0,'reinit')); foreach ($locale as $en => $de) { @@ -161,5 +177,6 @@ extends WikiPlugin // gettext module loaded: must load the LC_MESSAGES php hash } elseif (function_exists ('bindtextdomain')) { - include (FindLocalizedFile("LC_MESSAGES/phpwiki.php", 0,'reinit')); + include (FindFile("locale/$lang/LC_MESSAGES/phpwiki.php", 0,'reinit')); + //include (FindLocalizedFile("LC_MESSAGES/phpwiki.php", 0,'reinit')); // we already have a $locale, but maybe it's in the wrong language } elseif ($lang != $this->lang or empty($GLOBALS['locale'])) { @@ -194,8 +211,28 @@ extends WikiPlugin } + /** + * setlocale() switching with the gettext extension is by far too slow. + * So use the hash regardless if gettext is loaded or not. + */ + function fast_translate($text, $to_lang, $from_lang=false) { + if (!$from_lang) $from_lang = $this->lang; // current locale + if ($from_lang == $to_lang) return $text; + // setup hash from en => to_lang + if (!isset($this->_locales[$to_lang])) + $this->init_locale($to_lang); + if ($from_lang != 'en') { + // get reverse gettext: translate to english + $text = $this->translate_to_en($text, $from_lang); + } + return !empty($this->_locales[$to_lang][$text]) + ? $this->_locales[$to_lang][$text] + : $text; + } + + //FIXME! There's something wrong. function translate($text, $to_lang, $from_lang=false) { if (!$from_lang) $from_lang = $this->lang; // current locale if ($from_lang == $to_lang) return $text; - // speed up hash lookup. not needed for gettext module + // Speed up hash lookup. Not needed for gettext module if (!isset($this->_locales[$from_lang]) and !function_exists('bindtextdomain')) { $this->init_locale($from_lang); @@ -203,5 +240,5 @@ extends WikiPlugin if ($from_lang != 'en') { // get reverse gettext: translate to english - $en = $this->translate_to_en($text,$from_lang); + $en = $this->translate_to_en($text, $from_lang); // and then to target update_locale($to_lang); @@ -209,4 +246,6 @@ extends WikiPlugin update_locale($from_lang); } else { + // locale switching is very slow with the gettext extension. + // better use fast_translate if ($from_lang != $to_lang) { update_locale($to_lang); @@ -244,9 +283,15 @@ extends WikiPlugin $languages = array($languages); } - if (in_array('zh',$languages) or in_array('ja',$languages)) { - // if the current charset != utf-8 the text will not be displayed correctly - // but here we cannot change the header anymore. so we can decide to ignore them, + if (in_array('zh', $languages) or in_array('ja', $languages)) { + + // If the current charset != utf-8 the text will not be displayed correctly. + // But here we cannot change the header anymore. So we can decide to ignore them, // or display them with all the errors. - $GLOBALS['charset'] = 'utf-8'; + //FIXME: do iconv the ob + if ($GLOBALS['charset'] != 'utf-8') { + define('NEED_ICONV_TO', 'utf-8'); + //either the extension or external + //$GLOBALS['charset'] = 'utf-8'; + } } $to_lang = $languages[0]; @@ -259,5 +304,5 @@ extends WikiPlugin $url = ''; // google can only translate from english and french - if (in_array($from_lang,array('en','fr'))) { + if (in_array($from_lang, array('en', 'fr'))) { $url = "http://translate.google.com/translate"; $url .= "?langpair=" . urlencode($from_lang."|".$to_lang); @@ -265,12 +310,14 @@ extends WikiPlugin } // redirect or transclude? - if ($url) + if ($url) { return $request->redirect($url); + } return HTML(fmt("TODO: Google can only translate from english and french. Find a translation service for %s to language %s", WikiURL($pagename, false, true), $to_lang)); - } else + } else { return $this->error(fmt("%s is empty",$pagename)); } + } $pagelist = new PageList('', $exclude, $this->args); @@ -279,5 +326,6 @@ extends WikiPlugin if ($lang == $from_lang) continue; $field = "custom:$lang"; - $pagelist->addColumnObject(new _PageList_Column_customlang($field, $from_lang, $this)); + $pagelist->addColumnObject ( + new _PageList_Column_customlang($field, $from_lang, $this)); } if (!empty($string)) { @@ -287,10 +335,12 @@ extends WikiPlugin switch ($what) { case 'allpages': - $pagelist->addPages( $dbi->getAllPages($include_empty, $sortby, $limit) ); + $pagelist->addPages( $dbi->getAllPages($include_empty, $sortby, + $limit, $exclude) ); break; case 'pages': // not all pages, only the pgsrc pages if (!is_array($exclude)) - $exclude = $pagelist->explodePageList($exclude, false, $sortby, $limit); + $exclude = $pagelist->explodePageList($exclude, false, $sortby, + $limit, $exclude); $path = FindLocalizedFile(WIKI_PGSRC); $pgsrc = new fileSet($path); @@ -325,9 +375,11 @@ extends WikiPlugin break; // all Button texts, which need a localized .png - // where to get them from? templates/*.tmpl: Button() and WikiLink(?,'button') + // where to get them from? templates/*.tmpl: Button() + // and WikiLink(?,'button') // navbar links, actionpages, and admin requests case 'buttons': $buttons = $GLOBALS['AllActionPages']; - $fileset = new FileSet(FindFile("themes/MacOSX/buttons/en"), "*.png"); + $fileset = new FileSet(FindFile("themes/MacOSX/buttons/en"), + "*.png"); foreach ($fileset->getFiles() as $file) { $b = urldecode(substr($file, 0, -4)); @@ -365,5 +417,6 @@ class _PageList_Column_customlang extend if (is_object($page)) $text = $page->getName(); else $text = $page; - $trans = $this->_plugin->translate($text, $this->_field, $this->_from_lang); + $trans = $this->_plugin->fast_translate($text, $this->_field, + $this->_from_lang); // how to markup untranslated words and not existing pages? // untranslated: (TODO) link to translation editor @@ -371,13 +424,18 @@ class _PageList_Column_customlang extend (($this->_from_lang != 'en') and ($this->_field != 'en') and - ($trans == $this->_plugin->translate($text, 'en', $this->_from_lang)) + ($trans == $this->_plugin->fast_translate($text, 'en', + $this->_from_lang)) )) { global $WikiTheme; $link = $WikiTheme->linkUnknownWikiWord($trans); - if (!($this->_noT or $this->_nolinks) and $this->dbi->isWikiPage($trans)) { - $url = WikiURL($trans, array('action' => 'TranslateText','lang' => $this->_field)); + if (!($this->_noT or $this->_nolinks) + and $this->dbi->isWikiPage($trans)) + { + $url = WikiURL($trans, array('action' => 'TranslateText', + 'lang' => $this->_field)); $button = $WikiTheme->makeButton('T', $url); - $button->addTooltip(sprintf(_("Define the translation for %s in %s"), $trans, $this->_field)); + $button->addTooltip(sprintf(_("Define the translation for %s in %s"), + $trans, $this->_field)); $link = HTML::span($button); $link->setAttr('class', 'wikiunknown'); @@ -402,4 +460,7 @@ class _PageList_Column_customlang extend // $Log$ +// Revision 1.15 2005/01/25 08:06:47 rurban +// add fast_translate: setlocale() switching with the gettext extension is by far too slow; add default pagelist args +// // Revision 1.14 2004/07/08 20:30:07 rurban // plugin->run consistency: request as reference, added basepage. ------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | CVS: phpwiki/lib ziplib.php,1.42,1.43: 00133, Reini Urban |
|---|---|
| Next by Date: | CVS: phpwiki/lib/plugin RandomPage.php,1.12,1.13: 00133, Reini Urban |
| Previous by Thread: | CVS: phpwiki/lib ziplib.php,1.42,1.43i: 00133, Reini Urban |
| Next by Thread: | CVS: phpwiki/lib/plugin RandomPage.php,1.12,1.13: 00133, Reini Urban |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |