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