2 rcs_id('$Id: TranslateText.php,v 1.1 2004-03-17 11:42:37 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 pagename is the text to be translated.
26 * One required argument: lang
27 * Usually called from <?plugin _WikiTranslation ?>
30 * pagename="Some text in english" action=TranslateText lang=es
32 * @author: Reini Urban
35 require_once("lib/plugin/_WikiTranslation.php");
37 class WikiPlugin_TranslateText
38 extends WikiPlugin__WikiTranslation
41 return _("TranslateText");
44 function getDescription() {
45 return _("Define a translation for a specified text");
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
53 function getDefaultArguments() {
55 array( 'lang' => false,
56 'pagename' => '[pagename]',
61 function run($dbi, $argstr, $request, $basepage) {
62 extract($this->getArgs($argstr, $request));
64 return $this->error("This internal action page cannot viewed. You can only use it via the _WikiTranslation plugin.");
68 if (isset($translate['submit']) and $request->isPost()) {
69 $trans = $translate["content"];
70 if (empty($trans) or $trans == $pagename) {
71 $header = HTML(HTML::h2("Translation Error!"),
72 HTML::p("Your translated text is either empty or equal to the untranslated text. Please try again."));
74 //save translation in a users subpage
75 $user = $request->getUser();
76 $homepage = $user->_HomePagehandle;
77 $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . _("ContributedTranslations");
79 $page = $dbi->getPage($transpagename);
80 $current = $page->getCurrentRevision();
81 $version = $current->getVersion();
83 $text = $current->getPackedContent() . "\n";
84 $meta = $current->_data;
87 $meta = array('markup' => 2.0,
88 'author' => $user->getId());
91 $user->getId() . " " . Iso8601DateTime() . "\n" .
92 "* " . sprintf(_("Translate %s to %s in %s"),$pagename,
94 $meta['summary'] = sprintf(_("Translate %s to %s in %s"),substr($pagename,0,15),
95 substr($trans,0,15),$lang);
96 $page->save($text, $version + 1, $meta);
97 // TODO: admin notification
98 return HTML(HTML::h2("Thanks for adding this translation!"),
99 HTML::p("Your translated text doesn't yet appear in this PhpWiki, but the Administrator will pick it up and add to the installation."),
100 fmt("Your translation is stored in %s",WikiLink($transpagename)));
103 $trans = $this->translate($pagename,$lang,'en');
104 //Todo: google lookup or at least a google lookup button.
106 $header = HTML($header,fmt("From english to %s: ", HTML::strong($lang)));
108 $header = fmt("From english to %s: ", HTML::strong($lang));
109 $next_action = 'save';
110 $button_label = _("Translate");
112 $buttons = HTML::p(Button('submit:translate[submit]', $button_label, 'wikiadmin'),
113 Button('submit:translate[cancel]', _("Cancel"), 'button'));
114 return HTML::form(array('action' => $request->getPostURL(),
117 HTML::textarea(array('class' => 'wikiedit',
118 'name' => 'translate[content]',
119 'id' => 'translate[content]',
121 'cols' => $request->getPref('editWidth'),
122 'wrap' => 'virtual'),
124 HiddenInputs($request->getArgs(),
127 HiddenInputs(array('translate[action]' => $pagename,
128 'require_authority_for_post' => WIKIAUTH_BOGO,
134 // $Log: not supported by cvs2svn $
142 // c-hanging-comment-ender-p: nil
143 // indent-tabs-mode: nil