]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/TranslateText.php
Update getDescription
[SourceForge/phpwiki.git] / lib / plugin / TranslateText.php
1 <?php
2
3 /*
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 /**
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.
28  *
29  * Usually called from <<_WikiTranslation >>
30  * Contributed translation are stored in UsersPage/ContributedTranslations
31  *
32  * Examples:
33  *    pagename="Some text in english" action=TranslateText lang=es
34  *
35  * @author:  Reini Urban
36  */
37
38 require_once 'lib/plugin/_WikiTranslation.php';
39
40 class WikiPlugin_TranslateText
41     extends WikiPlugin__WikiTranslation
42 {
43     function getName()
44     {
45         return _("TranslateText");
46     }
47
48     function getDescription()
49     {
50         return _("Define a translation for a specified text.");
51     }
52
53     function getDefaultArguments()
54     {
55         return
56             array('lang' => false,
57                 'pagename' => '[pagename]',
58                 'translate' => false,
59             );
60     }
61
62     function run($dbi, $argstr, &$request, $basepage)
63     {
64         extract($this->getArgs($argstr, $request));
65         if (!$lang)
66             return $this->error(
67                 _("This internal action page cannot viewed.") . "\n" .
68                     _("You can only use it via the _WikiTranslation plugin."));
69
70         $this->lang = $lang;
71         //action=save
72         if (!empty($translate) and isset($translate['submit']) and $request->isPost()) {
73             $trans = $translate["content"];
74             if (empty($trans) or $trans == $pagename) {
75                 $header = HTML(HTML::h2(_("Translation Error!")),
76                     HTML::p(_("Your translated text is either empty or equal to the untranslated text. Please try again.")));
77             } else {
78                 //save translation in a users subpage
79                 $user = $request->getUser();
80                 $homepage = $user->_HomePagehandle;
81                 $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . _("ContributedTranslations");
82
83                 $page = $dbi->getPage($transpagename);
84                 $current = $page->getCurrentRevision();
85                 $version = $current->getVersion();
86                 if ($version) {
87                     $text = $current->getPackedContent() . "\n";
88                     $meta = $current->_data;
89                 } else {
90                     $text = '';
91                     $meta = array('markup' => 2.0,
92                         'author' => $user->getId());
93                 }
94                 $text .= $user->getId() . " " . Iso8601DateTime() . "\n" .
95                     "* " . sprintf(_("Translate ā€œ%sā€ to ā€œ%sā€ in *%s*"),
96                     $pagename, $trans, $lang);
97                 $text .= "\n  <verbatim>locale/po/$lang.po:\n  msgid \"" . $pagename . "\"\n  msgstr \"" . $trans . "\"\n  </verbatim>";
98                 $meta['summary'] = sprintf(_("Translate %s to %s in %s"),
99                     substr($pagename, 0, 15), substr($trans, 0, 15), $lang);
100                 $page->save($text, $version + 1, $meta);
101                 // TODO: admin notification
102                 return HTML(HTML::h2(_("Thanks for adding this translation!")),
103                     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                         WIKI_NAME)),
105                     fmt("Your translation is stored in %s", WikiLink($transpagename)));
106             }
107         }
108         $trans = $this->translate($pagename, $lang, 'en');
109         //Todo: google lookup or at least a google lookup button.
110         if (isset($header))
111             $header = HTML($header, fmt("From english to %s: ", HTML::strong($lang)));
112         else
113             $header = fmt("From english to %s: ", HTML::strong($lang));
114         $button_label = _("Translate");
115
116         $buttons = HTML::p(Button('submit:translate[submit]', $button_label, 'wikiadmin'),
117             Button('submit:translate[cancel]', _("Cancel"), 'button'));
118         return HTML::form(array('action' => $request->getPostURL(),
119                 'method' => 'post'),
120             $header,
121             HTML::textarea(array('class' => 'wikiedit',
122                     'name' => 'translate[content]',
123                     'id' => 'translate[content]',
124                     'rows' => 4,
125                     'cols' => $request->getPref('editWidth')
126                 ),
127                 $trans),
128             HiddenInputs($request->getArgs(),
129                 false,
130                 array('translate')),
131             HiddenInputs(array('translate[action]' => $pagename,
132                 'require_authority_for_post' => WIKIAUTH_BOGO,
133             )),
134             $buttons);
135     }
136 }
137
138 // Local Variables:
139 // mode: php
140 // tab-width: 8
141 // c-basic-offset: 4
142 // c-hanging-comment-ender-p: nil
143 // indent-tabs-mode: nil
144 // End: