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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 <<TranslateText >> line exists.
29 * Usually called from <<_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
43 function getDescription()
45 return _("Define a translation for a specified text.");
48 function getDefaultArguments()
51 array('lang' => false,
52 'pagename' => '[pagename]',
57 function run($dbi, $argstr, &$request, $basepage)
59 extract($this->getArgs($argstr, $request));
62 _("This internal action page cannot viewed.") . "\n" .
63 _("You can only use it via the _WikiTranslation plugin."));
67 if (!empty($translate) and isset($translate['submit']) and $request->isPost()) {
68 $trans = $translate["content"];
69 if (empty($trans) or $trans == $pagename) {
70 $header = HTML(HTML::h2(_("Translation Error!")),
71 HTML::p(_("Your translated text is either empty or equal to the untranslated text. Please try again.")));
73 //save translation in a users subpage
74 $user = $request->getUser();
75 $homepage = $user->_HomePagehandle;
76 $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . _("ContributedTranslations");
78 $page = $dbi->getPage($transpagename);
79 $current = $page->getCurrentRevision();
80 $version = $current->getVersion();
82 $text = $current->getPackedContent() . "\n";
83 $meta = $current->_data;
86 $meta = array('markup' => 2.0,
87 'author' => $user->getId());
89 $text .= $user->getId() . " " . Iso8601DateTime() . "\n" .
90 "* " . sprintf(_("Translate ā%sā to ā%sā in *%s*"),
91 $pagename, $trans, $lang);
92 $text .= "\n <verbatim>locale/po/$lang.po:\n msgid \"" . $pagename . "\"\n msgstr \"" . $trans . "\"\n </verbatim>";
93 $meta['summary'] = sprintf(_("Translate %s to %s in %s"),
94 substr($pagename, 0, 15), substr($trans, 0, 15), $lang);
95 $page->save($text, $version + 1, $meta);
96 // TODO: admin notification
97 return HTML(HTML::h2(_("Thanks for adding this translation!")),
98 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.",
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 $button_label = _("Translate");
111 $buttons = HTML::p(Button('submit:translate[submit]', $button_label, 'wikiadmin'),
112 Button('submit:translate[cancel]', _("Cancel"), 'button'));
113 return HTML::form(array('action' => $request->getPostURL(),
116 HTML::textarea(array('class' => 'wikiedit',
117 'name' => 'translate[content]',
118 'id' => 'translate[content]',
120 'cols' => $request->getPref('editWidth')
123 HiddenInputs($request->getArgs(),
126 HiddenInputs(array('translate[action]' => $pagename,
127 'require_authority_for_post' => WIKIAUTH_BOGO,
137 // c-hanging-comment-ender-p: nil
138 // indent-tabs-mode: nil