]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/TranslateText.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / TranslateText.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 <?plugin TranslateText ?> line exists.
28  *
29  * Usually called from <?plugin _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         return _("TranslateText");
45     }
46
47     function getDescription() {
48         return _("Define a translation for a specified text");
49     }
50
51     function getVersion() {
52         return preg_replace("/[Revision: $]/", '',
53                             "\$Revision$");
54     }
55
56     function getDefaultArguments() {
57         return 
58             array( 'lang'      => false,
59                    'pagename'  => '[pagename]',
60                    'translate' => false,
61                  );
62     }
63
64     function run($dbi, $argstr, &$request, $basepage) {
65         extract($this->getArgs($argstr, $request));
66         if (!$lang)
67             return $this->error(
68                 _("This internal action page cannot viewed.")."\n".
69                 _("You can only use it via the _WikiTranslation plugin."));
70            
71         $this->lang = $lang;
72         //action=save
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.")));
78             } else {
79                 //save translation in a users subpage
80                 $user = $request->getUser();
81                 $homepage = $user->_HomePagehandle;
82                 $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . _("ContributedTranslations");
83
84                 $page    = $dbi->getPage($transpagename);
85                 $current = $page->getCurrentRevision();
86                 $version = $current->getVersion();
87                 if ($version) {
88                     $text = $current->getPackedContent() . "\n";
89                     $meta = $current->_data;
90                 } else {
91                     $text = '';
92                     $meta = array('markup' => 2.0,
93                                   'author' => $user->getId());
94                 }
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.", 
105                                        WIKI_NAME)),
106                             fmt("Your translation is stored in %s",WikiLink($transpagename)));
107             }
108         }
109         $trans = $this->translate($pagename,$lang,'en');
110         //Todo: google lookup or at least a google lookup button.
111         if (isset($header))
112             $header = HTML($header,fmt("From english to %s: ", HTML::strong($lang)));
113         else
114             $header = fmt("From english to %s: ", HTML::strong($lang));
115         $button_label = _("Translate");
116
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(),
120                                 'method' => 'post'),
121                           $header,
122                           HTML::textarea(array('class' => 'wikiedit',
123                                                'name' => 'translate[content]',
124                                                'id'   => 'translate[content]',
125                                                'rows' => 4,
126                                                'cols' => $request->getPref('editWidth'),
127                                                'wrap' => 'virtual'),
128                                          $trans),
129                           HiddenInputs($request->getArgs(),
130                                         false,
131                                         array('translate')),
132                           HiddenInputs(array('translate[action]' => $pagename,
133                                              'require_authority_for_post' => WIKIAUTH_BOGO,
134                                              )),
135                           $buttons);
136        }
137 };
138
139 // $Log: not supported by cvs2svn $
140 // Revision 1.4  2004/05/18 13:58:39  rurban
141 // verbatim needs a linebreak
142 //
143 // Revision 1.3  2004/03/17 15:38:03  rurban
144 // more translations
145 //
146 // Revision 1.2  2004/03/17 12:04:36  rurban
147 // more docs
148 //
149 //
150
151 // For emacs users
152 // Local Variables:
153 // mode: php
154 // tab-width: 8
155 // c-basic-offset: 4
156 // c-hanging-comment-ender-p: nil
157 // indent-tabs-mode: nil
158 // End:
159 ?>