PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/i18n_v2/www_root/i18n_example_script.php

http://flaimo-php.googlecode.com/
PHP | 190 lines | 177 code | 10 blank | 3 comment | 7 complexity | 9a1242045ab2b263ad8bc168e8027298 MD5 | raw file
  1. <?php
  2. error_reporting(E_ALL);
  3. ob_start(); // you have to use output buffering, otherwise there's a problem with setting cookies/sessions
  4. header("content-type: text/html;charset=UTF-8 \r\n");
  5. session_start();
  6. mb_internal_encoding('UTF-8');
  7. mb_language('uni');
  8. function start_timer($event) {
  9. //printf("timer: %s<br>\n", $event);
  10. list($low, $high) = explode(' ', microtime());
  11. $t = $high + $low;
  12. flush();
  13. return $t;
  14. }
  15. function next_timer($start, $event) {
  16. list($low, $high) = explode(' ', microtime());
  17. $t = $high + $low;
  18. $used = $t - $start;
  19. sumTimer($used, false);
  20. printf('timer (%s): %8.4f', $event, $used);
  21. //printf("Page generated in %s %8.4f seconds", $event, $used);
  22. flush();
  23. return $t;
  24. }
  25. function sumTimer($time = 0, $show = false) {
  26. static $sum = 0;
  27. if($show == true) {
  28. printf('timer (sum): %8.4f', $sum);
  29. } else {
  30. $sum += $time;
  31. }
  32. }
  33. $t = start_timer("start Befehl 1");
  34. require_once '../inc/class.I18Nbase.inc.php';
  35. $englisch_translator = new I18Ntranslator('', new I18Nlocale('en'));
  36. $i18n_user =& $englisch_translator->getI18Nuser();
  37. if (isset($_POST['locale'])) {
  38. $i18n_user->setPrefLocale($_POST['locale']);
  39. } elseif (isset($_POST['timeformat'])) {
  40. $i18n_user->setPrefTimeFormat($_POST['timeformat']);
  41. } elseif (isset($_POST['measure'])) {
  42. $i18n_user->setPrefMeasureSystem($_POST['measure']);
  43. } // end if
  44. $translator = new I18Ntranslator();
  45. $measure = new I18Nmeasure('si');
  46. $format_date = new I18NformatDate();
  47. $format_number = new I18NformatNumber();
  48. $format_string = new I18NformatString();
  49. ?>
  50. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  51. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  52. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  53. <head>
  54. <title>i18n example-script</title>
  55. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  56. <style type="text/css">
  57. <!--
  58. @import url(css.css);
  59. -->
  60. </style>
  61. </head>
  62. <body>
  63. <h1><a href="https://sourceforge.net/projects/php-flp/">FLP – i18n</a> <small>(V2.3)</small></h1>
  64. <ul id="menu">
  65. <li><a href="#translator">Translator</a></li>
  66. <li><a href="#date">Date</a></li>
  67. <li><a href="#number">Number</a></li>
  68. <li><a href="#measure">Measure</a></li>
  69. <li><a href="#string">String</a></li>
  70. </ul>
  71. <p class="timer"><?php $t = next_timer($t, 'generating objects'); ?></p>
  72. <h2 id="translator">Translator <small>(<?php echo $translator->getI18NSetting('mode'); ?>)</small></h2>
  73. <h3>(current locale used: <?php echo $englisch_translator->_($translator->getTranslatorLocale()->getI18Nlocale()); ?>)</h3>
  74. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>#translator" name="select_locale" id="select_locale">
  75. <select name="locale" id="locale">
  76. <?php
  77. $possible_locales = array_keys($translator->getLocales());
  78. $current_locale = $translator->getTranslatorLocale();
  79. foreach ($possible_locales as $code) {
  80. $translator->changeLocale(new I18Nlocale($code));
  81. $selected = ($code == $current_locale->getI18Nlocale()) ? ' selected="selected"' : '';
  82. echo '<option value="' , $code , '"' , $selected , '>' , $translator->_($code) , '</option>';
  83. //echo '<option value="' , $code , '"' , $selected , '>' , mb_detect_encoding($translator->_($code)) , '</option>';
  84. } // end foreach
  85. $translator->changeLocale($current_locale);
  86. ?>
  87. </select>
  88. <input type="submit" name="Submit" value="Change language" />
  89. </form>
  90. <p class="sample" id="translator_sample">
  91. Translating ťno_records_foundŤ: <samp><?php echo $translator->_('no_records_found'); ?></samp>
  92. </p>
  93. <p class="timer"><?php $t = next_timer($t, 'translating'); ?></p>
  94. <h2 id="date">Date</h2>
  95. <h3>(current time format used: <?php echo $format_date->getTimeFormat(); ?>)</h3>
  96. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>#date" name="select_timeformat" id="select_timeformat">
  97. <select name="timeformat" id="timeformat">
  98. <?php
  99. foreach ($format_date->getPossibleTimeFormats() as $id => $name) {
  100. $selected = ($format_date->getTimeFormat() == $name) ? ' selected="selected"' : '';
  101. echo '<option value="' , $id , '"' , $selected , '>' , $name , '</option>';
  102. } // end foreach
  103. ?>
  104. </select>
  105. <input type="submit" name="Submit" value="Change time format" />
  106. </form>
  107. <?php
  108. $date = '2004-12-31 15:30:00';
  109. $timestamp = $format_date->ISOdatetimeToUnixtimestamp($date);
  110. ?>
  111. <p class="sample" id="formatdate_sample">
  112. Formating ť<?php echo $date; ?>Ť <small>(long)</small>: <samp><?php echo $format_date->longDateTime($timestamp); ?></samp>
  113. </p>
  114. <p class="sample" id="formatdate_sample">
  115. Formating ť<?php echo $date; ?>Ť <small>(middle)</small>: <samp><?php echo $format_date->middleDateTime($timestamp); ?></samp>
  116. </p>
  117. <p class="sample" id="formatdate_sample">
  118. Formating ť<?php echo $date; ?>Ť <small>(short)</small>: <samp><?php echo $format_date->shortDateTime($timestamp); ?></samp>
  119. </p>
  120. <p class="timer"><?php $t = next_timer($t, 'formating dates'); ?></p>
  121. <h2 id="number">Number</h2>
  122. <?php
  123. $number = 12345.678;
  124. $float = 0.567;
  125. $money = 0.56;
  126. ?>
  127. <p class="sample" id="formatnumber_sample">
  128. Formating ť<?php echo $number; ?>Ť: <samp><?php echo $format_number->number($number); ?></samp>
  129. </p>
  130. <p class="sample" id="formatnumber_sample">
  131. Formating ť<?php echo $float; ?>Ť <small>(percent)</small>: <samp><?php echo $format_number->percent($float); ?>%</samp>
  132. </p>
  133. <p class="sample" id="formatnumber_sample">
  134. Formating ť<?php echo $money; ?>Ť <small>(currency big)</small>: <samp><?php echo $format_number->currency($money, 'full', 'gb', TRUE); ?></samp>
  135. </p>
  136. <p class="sample" id="formatnumber_sample">
  137. Formating ť<?php echo $money; ?>Ť <small>(currency small)</small>: <samp><?php echo $format_number->currency($money, 'full', 'gb', FALSE); ?></samp>
  138. </p>
  139. <p class="sample" id="formatnumber_sample">
  140. Formating ť<?php echo $money; ?>Ť <small>(currency symbol left)</small>: <samp><?php echo $format_number->currency($money, 'symbol', 'gb', TRUE, 'before'); ?></samp>
  141. </p>
  142. <p class="timer"><?php $t = next_timer($t, 'formating numers'); ?></p>
  143. <h2 id="measure">Measure</h2>
  144. <h3>(current measure output format used: <?php echo $measure->getOutput(); ?>)</h3>
  145. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>#measure" name="select_measure" id="select_measure">
  146. <select name="measure" id="measure2">
  147. <?php
  148. $possible_formats =& $measure->getFormats();
  149. foreach ($possible_formats as $format) {
  150. $translator->changeLocale(new I18Nlocale($code));
  151. $selected = ($format == $measure->getOutput()) ? ' selected="selected"' : '';
  152. echo '<option value="' , $format , '"' , $selected , '>' , $format , '</option>';
  153. } // end foreach
  154. ?>
  155. </select>
  156. <input type="submit" name="Submit" value="Change measure output format" />
  157. </form>
  158. <?php
  159. $number = 30000;
  160. ?>
  161. <p class="sample" id="formatmeasure_sample">
  162. Formating ť<?php echo $number; ?> mmŤ: <samp><?php echo $measure->linear($number, 0, 0) , ' ' , $measure->Unit(2); ?></samp>
  163. </p>
  164. <p class="timer"><?php $t = next_timer($t, 'formating measure'); ?></p>
  165. <h2 id="string">String</h2>
  166. <?php
  167. $string_1 = 'I know a lot of Buffy fanpages on the WWW.';
  168. $string_2 = 'Most of them have Fanfiction stories you can download, but nearly all of them are bullshit.';
  169. ?>
  170. <p class="sample" id="formatstring_sample">
  171. Stripping bad words: <samp><?php echo $format_string->wordFilter($string_2, TRUE); ?></samp>
  172. </p>
  173. <p class="sample" id="formatstring_sample">
  174. Highlighting special words: <samp><?php echo $format_string->highlightSpecialWords($string_1); ?></samp>
  175. </p>
  176. <p class="timer"><?php $t = next_timer($t, 'formating strings'); ?></p>
  177. <p id="sum"><?php $t = sumTimer(0,true); ?></p>
  178. </body>
  179. </html>
  180. <?php ob_end_flush(); ?>