cvs: pear /I18N/docs I18N_DateTime.php I18N_Message.php I18N_Message_Translate.php I18N_Message_Translate.tpl I18N_Negotiator.php
| From: | Wolfram Kriesing | Date: | Fri, 22 Nov 2002 13:44:56 +0000 |
| Subject: | cvs: pear /I18N/docs I18N_DateTime.php I18N_Message.php I18N_Message_Translate.php I18N_Message_Translate.tpl I18N_Negotiator.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7521@lists.php.net to get a copy of this message | ||
cain Fri Nov 22 08:44:56 2002 EDT
Added files:
/pear/I18N/docs I18N_DateTime.php I18N_Message.php
I18N_Message_Translate.php
I18N_Message_Translate.tpl I18N_Negotiator.php
Log:
- all examples go in 'docs' :-)
Index: pear/I18N/docs/I18N_DateTime.php +++ pear/I18N/docs/I18N_DateTime.php <?php // // // ini_set('include_path',ini_get('include_path').':../..'); require_once 'I18N/DateTime.php'; $dateTime = new I18N_DateTime( 'es_ES' ); //////////////////////////////////////////// // // DATE and TIME // // myPrint('<h1>DATE and TIME</h1>'); // // get the time now in format DEFAULT // myPrint( $dateTime->format() ); // // get the time now in format FULL // myPrint( $dateTime->format( mktime(0,0,0,1,12,12) , I18N_DATETIME_FULL ) ); // or like this $dateTime->setFormat( I18N_DATETIME_FULL ); myPrint( $dateTime->format() ); // all possible formats myPrint( $dateTime->format( time() , I18N_DATETIME_SHORT ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_MEDIUM ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_DEFAULT ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_LONG ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_FULL ) ); //////////////////////////////////////////// // // DATE only // // myPrint('<h1>DATE only</h1>'); // // get the time now in format DEFAULT // myPrint( $dateTime->formatDate() ); // // get the time now in format FULL // myPrint( $dateTime->formatDate( time() , I18N_DATETIME_FULL ) ); // or like this $dateTime->setFormat( I18N_DATETIME_FULL ); myPrint( $dateTime->formatDate() ); // all possible formats myPrint( $dateTime->formatDate( time() , I18N_DATETIME_SHORT ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_MEDIUM ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_DEFAULT ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_LONG ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_FULL ) ); //////////////////////////////////////////// // // TIME only // // myPrint('<h1>TIME only</h1>'); // // get the time now in format DEFAULT // myPrint( $dateTime->formatTime() ); // // get the time now in format FULL // myPrint( $dateTime->formatTime( time() , I18N_DATETIME_FULL ) ); // or like this $dateTime->setFormat( I18N_DATETIME_FULL ); myPrint( $dateTime->formatTime() ); // all possible formats myPrint( $dateTime->formatTime( time() , I18N_DATETIME_SHORT ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_MEDIUM ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_DEFAULT ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_LONG ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_FULL ) ); /***************************** * * CUSTOM formats * */ myPrint('<h1>CUSTOM format</h1>'); // // get the time now in a custom format // $myFormat = $dateTime->setFormat('l, d.m.Y - H:i:s \y\e\a\h'); myPrint( $dateTime->format() ); // switch back to default format $dateTime->setFormat(); myPrint( $dateTime->format() ); // switch back to myFormat $dateTime->setFormat( $myFormat ); myPrint( $dateTime->formatDate() ); myPrint('<h1>CUSTOM time-format</h1>'); // // set custom time format only // $myTimeFormat = $dateTime->setTimeFormat('H \U\h\r i \M\i\n\u\t\e\n \u\n\d s \S\e\k\u\n\d\e\n'); myPrint( $dateTime->formatTime() ); // switch back to default format $dateTime->setFormat(); myPrint( $dateTime->format() ); // switch back to myFormat $dateTime->setFormat( $myTimeFormat ); myPrint( $dateTime->formatTime() ); function myPrint( $string ) { print "$string<br><br>"; } ?> Index: pear/I18N/docs/I18N_Message.php +++ pear/I18N/docs/I18N_Message.php <html> <body> <font color="red"> please get the sql-file from <a href="http://wolfram.kriesing.de/libs/php/SimpleTemplate/examples/translate.sql">here</a> to make the translate-method work properly<br> this example requires >=PHP 4.1 </font> <br><br> <?php ini_set('include_path',ini_get('include_path').':../..'); /** * * test of I18N_Message_Common * */ print '<h1>TEST I18N_Messages_Common</h1>'; require_once( 'I18N/Messages/Common.php' ); $strings[] = 'This is a test for all of you out there!'; $strings[] = 'Das ist ein Test für Euch alle da draussen!'; $strings[] = 'Esto es una prueba para todos vosotros ahi!'; $strings[] = 'je tu il elle nous vous - need french input here :-)'; $strings[] = 'Questo è un test per tutti voi là fuori!'; foreach( $strings as $aString ) print "<b>$aString</b> --- seems to be of the language: <b>".I18N_Messages_Common::determineLanguage($aString).'</b><br>'; echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo 'determine language of:<input name="langString" size="50" '; echo 'value="'.(isset($_REQUEST['langString'])?$_REQUEST['langString']:'What language is this?').'">'; echo '<input type="submit"><br>'; if( $_REQUEST['langString'] ) { echo 'I18N_Messages_Common::determineLanguage says it is: <b>'; echo I18N_Messages_Common::determineLanguage($_REQUEST['langString']).'</b>'; } echo "</form>"; /** * * test of Message_Translate * * DB file: http://wolfram.kriesing.de/libs/php/examples/SimpleTemplate/translate.sql * */ print '<h1>TEST I18N_Messages_Translate</h1>'; require_once( 'I18N/Messages/Translate.php' ); $translate = new I18N_Messages_Translate( 'mysql://root@localhost/test' ); $translated[] = $translate->simpleTranslate( 'source code' , 'de' ); $translated[] = $translate->translate( 'translate (i.e. into ($someVar-or any other string))' , 'de' ); $translated[] = $translate->translateMarkUpString( $input , 'de' ); foreach( $translated as $aTrans ) print "$aTrans<br>"; print_r( $translate->getAll( 'de' ) ); ?> </body> </html> Index: pear/I18N/docs/I18N_Message_Translate.php +++ pear/I18N/docs/I18N_Message_Translate.php <?php ini_set('include_path',ini_get('include_path').':../..'); /** * * test of Message_Translate * * DB file: http://wolfram.kriesing.de/libs/php/examples/SimpleTemplate/translate.sql * */ require_once( 'HTML/IT.php' ); $tpl = new IntegratedTemplate( '.' ); $tpl->loadTemplatefile( 'I18N_Message_Translate.tpl' ); $langLinks = '<a href="'.$_SERVER['PHP_SELF'].'?lang=de">german</a>, '. '<a href="'.$_SERVER['PHP_SELF'].'?lang=en">english</a>'; $tpl->setVariable( 'langLinks' , $langLinks ); $tpl->setVariable( 'sourceCode' , $sourceCode ); $tplString = $tpl->get(); // // the actual translate stuff // require_once( 'I18N/Messages/Translate.php' ); $db = DB::connect('mysql://root@localhost/test'); $translate = new I18N_Messages_Translate( $db ); print $translate->translateMarkUpString( $tplString , $_REQUEST['lang']?$_REQUEST['lang']:'en' ); ?> Index: pear/I18N/docs/I18N_Message_Translate.tpl +++ pear/I18N/docs/I18N_Message_Translate.tpl <html> <body> <font color="red"> please get the sql-file from <a href="http://wolfram.kriesing.de/libs/php/SimpleTemplate/examples/translate.sql">here</a> to make the translate-method work properly<br> this example requires >=PHP 4.1 </font> <h1>TEST of I18N_Messages_Translate</h1> This page uses IT[X] as the template engine, this example shows that one can easily use this class to translate templates, HTML/XML-strings or entire pages.<br><br> <b>The following text pieces will be translated automatically, use the links to translate into another language:</b><br><br> <br> translate (i.e. into {langLinks})<br><br> here additionally used Features:<br><br> source code<br><br> english<br><br> german<br><br> translate does by the way also convert everything to proper HTML if you want to, but you can maintain it without that in the DB<br><br> {sourceCode} </body> </html> Index: pear/I18N/docs/I18N_Negotiator.php +++ pear/I18N/docs/I18N_Negotiator.php <?php ini_set('include_path',ini_get('include_path').':../..'); /** * * test of I18N_Negotiator * */ print 'TEST I18N_Negotiator<br><br>'; require_once( 'I18N/Negotiator.php' ); $neg = new I18N_Negotiator; $execute = array(); $execute[] = '$lang = $neg->getLanguageMatch()'; $execute[] = '$country = $neg->getCountryMatch($lang)'; $execute[] = '$neg->getVariantInfo($lang)'; $execute[] = '$neg->getCharsetMatch()'; $execute[] = '$neg->getCountryName($country)'; $execute[] = '$neg->getLanguageName($lang)'; echo '<table border="1">'; foreach( $execute as $aExecute ) { eval('$result='.$aExecute.';'); print "<tr><td>$aExecute </td><td> $result</td></tr>"; } echo '</table>'; ?>
Index: pear/I18N/docs/I18N_DateTime.php +++ pear/I18N/docs/I18N_DateTime.php <?php // // // ini_set('include_path',ini_get('include_path').':../..'); require_once 'I18N/DateTime.php'; $dateTime = new I18N_DateTime( 'es_ES' ); //////////////////////////////////////////// // // DATE and TIME // // myPrint('<h1>DATE and TIME</h1>'); // // get the time now in format DEFAULT // myPrint( $dateTime->format() ); // // get the time now in format FULL // myPrint( $dateTime->format( mktime(0,0,0,1,12,12) , I18N_DATETIME_FULL ) ); // or like this $dateTime->setFormat( I18N_DATETIME_FULL ); myPrint( $dateTime->format() ); // all possible formats myPrint( $dateTime->format( time() , I18N_DATETIME_SHORT ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_MEDIUM ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_DEFAULT ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_LONG ) ); myPrint( $dateTime->format( time() , I18N_DATETIME_FULL ) ); //////////////////////////////////////////// // // DATE only // // myPrint('<h1>DATE only</h1>'); // // get the time now in format DEFAULT // myPrint( $dateTime->formatDate() ); // // get the time now in format FULL // myPrint( $dateTime->formatDate( time() , I18N_DATETIME_FULL ) ); // or like this $dateTime->setFormat( I18N_DATETIME_FULL ); myPrint( $dateTime->formatDate() ); // all possible formats myPrint( $dateTime->formatDate( time() , I18N_DATETIME_SHORT ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_MEDIUM ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_DEFAULT ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_LONG ) ); myPrint( $dateTime->formatDate( time() , I18N_DATETIME_FULL ) ); //////////////////////////////////////////// // // TIME only // // myPrint('<h1>TIME only</h1>'); // // get the time now in format DEFAULT // myPrint( $dateTime->formatTime() ); // // get the time now in format FULL // myPrint( $dateTime->formatTime( time() , I18N_DATETIME_FULL ) ); // or like this $dateTime->setFormat( I18N_DATETIME_FULL ); myPrint( $dateTime->formatTime() ); // all possible formats myPrint( $dateTime->formatTime( time() , I18N_DATETIME_SHORT ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_MEDIUM ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_DEFAULT ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_LONG ) ); myPrint( $dateTime->formatTime( time() , I18N_DATETIME_FULL ) ); /***************************** * * CUSTOM formats * */ myPrint('<h1>CUSTOM format</h1>'); // // get the time now in a custom format // $myFormat = $dateTime->setFormat('l, d.m.Y - H:i:s \y\e\a\h'); myPrint( $dateTime->format() ); // switch back to default format $dateTime->setFormat(); myPrint( $dateTime->format() ); // switch back to myFormat $dateTime->setFormat( $myFormat ); myPrint( $dateTime->formatDate() ); myPrint('<h1>CUSTOM time-format</h1>'); // // set custom time format only // $myTimeFormat = $dateTime->setTimeFormat('H \U\h\r i \M\i\n\u\t\e\n \u\n\d s \S\e\k\u\n\d\e\n'); myPrint( $dateTime->formatTime() ); // switch back to default format $dateTime->setFormat(); myPrint( $dateTime->format() ); // switch back to myFormat $dateTime->setFormat( $myTimeFormat ); myPrint( $dateTime->formatTime() ); function myPrint( $string ) { print "$string<br><br>"; } ?> Index: pear/I18N/docs/I18N_Message.php +++ pear/I18N/docs/I18N_Message.php <html> <body> <font color="red"> please get the sql-file from <a href="http://wolfram.kriesing.de/libs/php/SimpleTemplate/examples/translate.sql">here</a> to make the translate-method work properly<br> this example requires >=PHP 4.1 </font> <br><br> <?php ini_set('include_path',ini_get('include_path').':../..'); /** * * test of I18N_Message_Common * */ print '<h1>TEST I18N_Messages_Common</h1>'; require_once( 'I18N/Messages/Common.php' ); $strings[] = 'This is a test for all of you out there!'; $strings[] = 'Das ist ein Test für Euch alle da draussen!'; $strings[] = 'Esto es una prueba para todos vosotros ahi!'; $strings[] = 'je tu il elle nous vous - need french input here :-)'; $strings[] = 'Questo è un test per tutti voi là fuori!'; foreach( $strings as $aString ) print "<b>$aString</b> --- seems to be of the language: <b>".I18N_Messages_Common::determineLanguage($aString).'</b><br>'; echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo 'determine language of:<input name="langString" size="50" '; echo 'value="'.(isset($_REQUEST['langString'])?$_REQUEST['langString']:'What language is this?').'">'; echo '<input type="submit"><br>'; if( $_REQUEST['langString'] ) { echo 'I18N_Messages_Common::determineLanguage says it is: <b>'; echo I18N_Messages_Common::determineLanguage($_REQUEST['langString']).'</b>'; } echo "</form>"; /** * * test of Message_Translate * * DB file: http://wolfram.kriesing.de/libs/php/examples/SimpleTemplate/translate.sql * */ print '<h1>TEST I18N_Messages_Translate</h1>'; require_once( 'I18N/Messages/Translate.php' ); $translate = new I18N_Messages_Translate( 'mysql://root@localhost/test' ); $translated[] = $translate->simpleTranslate( 'source code' , 'de' ); $translated[] = $translate->translate( 'translate (i.e. into ($someVar-or any other string))' , 'de' ); $translated[] = $translate->translateMarkUpString( $input , 'de' ); foreach( $translated as $aTrans ) print "$aTrans<br>"; print_r( $translate->getAll( 'de' ) ); ?> </body> </html> Index: pear/I18N/docs/I18N_Message_Translate.php +++ pear/I18N/docs/I18N_Message_Translate.php <?php ini_set('include_path',ini_get('include_path').':../..'); /** * * test of Message_Translate * * DB file: http://wolfram.kriesing.de/libs/php/examples/SimpleTemplate/translate.sql * */ require_once( 'HTML/IT.php' ); $tpl = new IntegratedTemplate( '.' ); $tpl->loadTemplatefile( 'I18N_Message_Translate.tpl' ); $langLinks = '<a href="'.$_SERVER['PHP_SELF'].'?lang=de">german</a>, '. '<a href="'.$_SERVER['PHP_SELF'].'?lang=en">english</a>'; $tpl->setVariable( 'langLinks' , $langLinks ); $tpl->setVariable( 'sourceCode' , $sourceCode ); $tplString = $tpl->get(); // // the actual translate stuff // require_once( 'I18N/Messages/Translate.php' ); $db = DB::connect('mysql://root@localhost/test'); $translate = new I18N_Messages_Translate( $db ); print $translate->translateMarkUpString( $tplString , $_REQUEST['lang']?$_REQUEST['lang']:'en' ); ?> Index: pear/I18N/docs/I18N_Message_Translate.tpl +++ pear/I18N/docs/I18N_Message_Translate.tpl <html> <body> <font color="red"> please get the sql-file from <a href="http://wolfram.kriesing.de/libs/php/SimpleTemplate/examples/translate.sql">here</a> to make the translate-method work properly<br> this example requires >=PHP 4.1 </font> <h1>TEST of I18N_Messages_Translate</h1> This page uses IT[X] as the template engine, this example shows that one can easily use this class to translate templates, HTML/XML-strings or entire pages.<br><br> <b>The following text pieces will be translated automatically, use the links to translate into another language:</b><br><br> <br> translate (i.e. into {langLinks})<br><br> here additionally used Features:<br><br> source code<br><br> english<br><br> german<br><br> translate does by the way also convert everything to proper HTML if you want to, but you can maintain it without that in the DB<br><br> {sourceCode} </body> </html> Index: pear/I18N/docs/I18N_Negotiator.php +++ pear/I18N/docs/I18N_Negotiator.php <?php ini_set('include_path',ini_get('include_path').':../..'); /** * * test of I18N_Negotiator * */ print 'TEST I18N_Negotiator<br><br>'; require_once( 'I18N/Negotiator.php' ); $neg = new I18N_Negotiator; $execute = array(); $execute[] = '$lang = $neg->getLanguageMatch()'; $execute[] = '$country = $neg->getCountryMatch($lang)'; $execute[] = '$neg->getVariantInfo($lang)'; $execute[] = '$neg->getCharsetMatch()'; $execute[] = '$neg->getCountryName($country)'; $execute[] = '$neg->getLanguageName($lang)'; echo '<table border="1">'; foreach( $execute as $aExecute ) { eval('$result='.$aExecute.';'); print "<tr><td>$aExecute </td><td> $result</td></tr>"; } echo '</table>'; ?>