logo       


CVS: phpwiki/lib/plugin TranslateText.php,NONE,1.1: msg#00110

Subject: CVS: phpwiki/lib/plugin TranslateText.php,NONE,1.1
Update of /cvsroot/phpwiki/phpwiki/lib/plugin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17878/lib/plugin

Added Files:
        TranslateText.php 
Log Message:
action plugin to store user contributed translations via <?plugin 
_WikiTranslation ?>
todo: admin email notification


--- NEW FILE: TranslateText.php ---
<?php // -*-php-*-
rcs_id('$Id: TranslateText.php,v 1.1 2004/03/17 11:42:37 rurban Exp $');
/*
 Copyright 2004 $ThePhpWikiProgrammingTeam

 This file is part of PhpWiki.

 PhpWiki is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 PhpWiki is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with PhpWiki; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * TranslateText:  Translation helper
 * The pagename is the text to be translated.
 * One required argument: lang
 * Usually called from <?plugin _WikiTranslation ?>
 *
 * Examples:
 *    pagename="Some text in english" action=TranslateText lang=es
 *
 * @author:  Reini Urban
 */

require_once("lib/plugin/_WikiTranslation.php");

class WikiPlugin_TranslateText
extends WikiPlugin__WikiTranslation
{
    function getName() {
        return _("TranslateText");
    }

    function getDescription() {
        return _("Define a translation for a specified text");
    }

    function getVersion() {
        return preg_replace("/[Revision: $]/", '',
                            "\$Revision: 1.1 $");
    }

    function getDefaultArguments() {
        return 
            array( 'lang'      => false,
                   'pagename'  => '[pagename]',
                   'translate' => false,
                 );
    }

    function run($dbi, $argstr, $request, $basepage) {
        extract($this->getArgs($argstr, $request));
        if (!$lang)
            return $this->error("This internal action page cannot viewed. You 
can only use it via the _WikiTranslation plugin.");
            
        $this->lang = $lang;
        //action=save
        if (isset($translate['submit']) and $request->isPost()) {
            $trans = $translate["content"];
            if (empty($trans) or $trans == $pagename) {
                $header = HTML(HTML::h2("Translation Error!"),
                               HTML::p("Your translated text is either empty or 
equal to the untranslated text. Please try again."));
            } else {
                //save translation in a users subpage
                $user = $request->getUser();
                $homepage = $user->_HomePagehandle;
                $transpagename = $homepage->getName() . SUBPAGE_SEPARATOR . 
_("ContributedTranslations");

                $page    = $dbi->getPage($transpagename);
                $current = $page->getCurrentRevision();
                $version = $current->getVersion();
                if ($version) {
                    $text = $current->getPackedContent() . "\n";
                    $meta = $current->_data;
                } else {
                    $text = '';
                    $meta = array('markup' => 2.0,
                                  'author' => $user->getId());
                }
                $text = $text .
                        $user->getId() . " " . Iso8601DateTime() . "\n" .
                        "* " . sprintf(_("Translate %s to %s in %s"),$pagename,
                                                                     
$trans,$lang);
                $meta['summary'] = sprintf(_("Translate %s to %s in 
%s"),substr($pagename,0,15),
                                           substr($trans,0,15),$lang);
                $page->save($text, $version + 1, $meta);
                // TODO: admin notification
                return HTML(HTML::h2("Thanks for adding this translation!"),
                            HTML::p("Your translated text doesn't yet appear in 
this PhpWiki, but the Administrator will pick it up and add to the 
installation."),
                            fmt("Your translation is stored in 
%s",WikiLink($transpagename)));
            }
        }
        $trans = $this->translate($pagename,$lang,'en');
        //Todo: google lookup or at least a google lookup button.
        if (isset($header))
            $header = HTML($header,fmt("From english to %s: ", 
HTML::strong($lang)));
        else
            $header = fmt("From english to %s: ", HTML::strong($lang));
        $next_action = 'save';
        $button_label = _("Translate");

        $buttons = HTML::p(Button('submit:translate[submit]', $button_label, 
'wikiadmin'),
                           Button('submit:translate[cancel]', _("Cancel"), 
'button'));
        return HTML::form(array('action' => $request->getPostURL(),
                                'method' => 'post'),
                          $header,
                          HTML::textarea(array('class' => 'wikiedit',
                                               'name' => 'translate[content]',
                                               'id'   => 'translate[content]',
                                               'rows' => 4,
                                               'cols' => 
$request->getPref('editWidth'),
                                               'wrap' => 'virtual'),
                                         $trans),
                          HiddenInputs($request->getArgs(),
                                        false,
                                        array('translate')),
                          HiddenInputs(array('translate[action]' => $pagename,
                                             'require_authority_for_post' => 
WIKIAUTH_BOGO,
                                             )),
                          $buttons);
       }
};

// $Log: TranslateText.php,v $
// Revision 1.1  2004/03/17 11:42:37  rurban
// action plugin to store user contributed translations via <?plugin 
_WikiTranslation ?>
// todo: admin email notification
//
//

// For emacs users
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click


Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosting, windows, cisco ...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe