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));
68 _("This internal action page cannot viewed.")."\n".
69 _("You can only use it via the _WikiTranslation plugin."));
73 if (!empty($translate) and isset($translate['submit']) and $request->isPost()) {
74 $trans = $translate["content"];
75 if (empty($trans) or $trans == $pagename) {
76 $header = HTML(HTML::h2(_("Translation Error!")),
77 HTML::p(_("Your translated text is either empty or equal to the untranslated text. Please try again.")));
79 //save translation in a users subpage
80 $user = $request->getUser();
81 $homepage = $user->_HomePagehandle;
82 $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . _("ContributedTranslations");
84 $page = $dbi->getPage($transpagename);
85 $current = $page->getCurrentRevision();
86 $version = $current->getVersion();
88 $text = $current->getPackedContent() . "\n";
89 $meta = $current->_data;
92 $meta = array('markup' => 2.0,
93 'author' => $user->getId());
95 $text .= $user->getId() . " " . Iso8601DateTime() . "\n" .
96 "* " . sprintf(_("Translate '%s' to '%s' in *%s*"),
97 $pagename, $trans, $lang);
98 $text .= "\n <verbatim>locale/po/$lang.po:\n msgid \"".$pagename."\"\n msgstr \"".$trans."\"\n </verbatim>";
99 $meta['summary'] = sprintf(_("Translate %s to %s in %s"),
100 substr($pagename,0,15),substr($trans,0,15),$lang);
101 $page->save($text, $version + 1, $meta);
102 // TODO: admin notification
103 return HTML(HTML::h2(_("Thanks for adding this translation!")),
104 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.",
106 fmt("Your translation is stored in %s",WikiLink($transpagename)));
109 $trans = $this->translate($pagename,$lang,'en');
110 //Todo: google lookup or at least a google lookup button.
112 $header = HTML($header,fmt("From english to %s: ", HTML::strong($lang)));
114 $header = fmt("From english to %s: ", HTML::strong($lang));
115 $button_label = _("Translate");
117 $buttons = HTML::p(Button('submit:translate[submit]', $button_label, 'wikiadmin'),
118 Button('submit:translate[cancel]', _("Cancel"), 'button'));
119 return HTML::form(array('action' => $request->getPostURL(),
122 HTML::textarea(array('class' => 'wikiedit',
123 'name' => 'translate[content]',
124 'id' => 'translate[content]',
126 'cols' => $request->getPref('editWidth'),
127 'wrap' => 'virtual'),
129 HiddenInputs($request->getArgs(),
132 HiddenInputs(array('translate[action]' => $pagename,
133 'require_authority_for_post' => WIKIAUTH_BOGO,
139 // $Log: not supported by cvs2svn $
140 // Revision 1.4 2004/05/18 13:58:39 rurban
141 // verbatim needs a linebreak
143 // Revision 1.3 2004/03/17 15:38:03 rurban
146 // Revision 1.2 2004/03/17 12:04:36 rurban
156 // c-hanging-comment-ender-p: nil
157 // indent-tabs-mode: nil