2 rcs_id('$Id: TranslateText.php,v 1.2 2004-03-17 12:04:36 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * TranslateText: Translation helper
25 * The (bogus) pagename is the text to be translated.
26 * One required argument: lang
27 * Requires that an action page with the <?plugin TranslateText ?> line exists.
29 * Usually called from <?plugin _WikiTranslation ?>
30 * Contributed translation are stored in UsersPage/ContributedTranslations
33 * pagename="Some text in english" action=TranslateText lang=es
35 * @author: Reini Urban
38 require_once("lib/plugin/_WikiTranslation.php");
40 class WikiPlugin_TranslateText
41 extends WikiPlugin__WikiTranslation
44 return _("TranslateText");
47 function getDescription() {
48 return _("Define a translation for a specified text");
51 function getVersion() {
52 return preg_replace("/[Revision: $]/", '',
56 function getDefaultArguments() {
58 array( 'lang' => false,
59 'pagename' => '[pagename]',
64 function run($dbi, $argstr, $request, $basepage) {
65 extract($this->getArgs($argstr, $request));
67 return $this->error("This internal action page cannot viewed. You can only use it via the _WikiTranslation plugin.");
71 if (!empty($translate) and isset($translate['submit']) and $request->isPost()) {
72 $trans = $translate["content"];
73 if (empty($trans) or $trans == $pagename) {
74 $header = HTML(HTML::h2(_("Translation Error!")),
75 HTML::p(_("Your translated text is either empty or equal to the untranslated text. Please try again.")));
77 //save translation in a users subpage
78 $user = $request->getUser();
79 $homepage = $user->_HomePagehandle;
80 $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . _("ContributedTranslations");
82 $page = $dbi->getPage($transpagename);
83 $current = $page->getCurrentRevision();
84 $version = $current->getVersion();
86 $text = $current->getPackedContent() . "\n";
87 $meta = $current->_data;
90 $meta = array('markup' => 2.0,
91 'author' => $user->getId());
94 $user->getId() . " " . Iso8601DateTime() . "\n" .
95 "* " . sprintf(_("Translate %s to %s in %s"),$pagename,
97 $meta['summary'] = sprintf(_("Translate %s to %s in %s"),substr($pagename,0,15),
98 substr($trans,0,15),$lang);
99 $page->save($text, $version + 1, $meta);
100 // TODO: admin notification
101 return HTML(HTML::h2(_("Thanks for adding this translation!")),
102 HTML::p(fmt("Your translated text doesn't yet appear in this %s, but the Administrator will pick it up and add to the installation.",
104 fmt("Your translation is stored in %s",WikiLink($transpagename)));
107 $trans = $this->translate($pagename,$lang,'en');
108 //Todo: google lookup or at least a google lookup button.
110 $header = HTML($header,fmt("From english to %s: ", HTML::strong($lang)));
112 $header = fmt("From english to %s: ", HTML::strong($lang));
113 $button_label = _("Translate");
115 $buttons = HTML::p(Button('submit:translate[submit]', $button_label, 'wikiadmin'),
116 Button('submit:translate[cancel]', _("Cancel"), 'button'));
117 return HTML::form(array('action' => $request->getPostURL(),
120 HTML::textarea(array('class' => 'wikiedit',
121 'name' => 'translate[content]',
122 'id' => 'translate[content]',
124 'cols' => $request->getPref('editWidth'),
125 'wrap' => 'virtual'),
127 HiddenInputs($request->getArgs(),
130 HiddenInputs(array('translate[action]' => $pagename,
131 'require_authority_for_post' => WIKIAUTH_BOGO,
137 // $Log: not supported by cvs2svn $
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil