pigs_dropin.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. Copyright (c) 2003,2004,2005,2009 Danilo Segan <danilo@kvota.net>.
  4. Copyright (c) 2005,2006 Steven Armstrong <sa@c-area.ch>
  5. This file is part of PHP-gettext.
  6. PHP-gettext is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. PHP-gettext is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with PHP-gettext; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. error_reporting(E_ALL | E_STRICT);
  19. // define constants
  20. define('PROJECT_DIR', realpath('./'));
  21. define('LOCALE_DIR', PROJECT_DIR .'/locale');
  22. define('DEFAULT_LOCALE', 'en_US');
  23. require_once('../gettext.inc');
  24. $supported_locales = array('en_US', 'sr_CS', 'de_CH');
  25. $encoding = 'UTF-8';
  26. $locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;
  27. // gettext setup
  28. T_setlocale(LC_MESSAGES, $locale);
  29. // Set the text domain as 'messages'
  30. $domain = 'messages';
  31. bindtextdomain($domain, LOCALE_DIR);
  32. // bind_textdomain_codeset is supported only in PHP 4.2.0+
  33. if (function_exists('bind_textdomain_codeset'))
  34. bind_textdomain_codeset($domain, $encoding);
  35. textdomain($domain);
  36. header("Content-type: text/html; charset=$encoding");
  37. ?>
  38. <html>
  39. <head>
  40. <title>PHP-gettext dropin example</title>
  41. </head>
  42. <body>
  43. <h1>PHP-gettext as a dropin replacement</h1>
  44. <p>Example showing how to use PHP-gettext as a dropin replacement for the native gettext library.</p>
  45. <?php
  46. print "<p>";
  47. foreach($supported_locales as $l) {
  48. print "[<a href=\"?lang=$l\">$l</a>] ";
  49. }
  50. print "</p>\n";
  51. if (!locale_emulation()) {
  52. print "<p>locale '$locale' is supported by your system, using native gettext implementation.</p>\n";
  53. }
  54. else {
  55. print "<p>locale '$locale' is _not_ supported on your system, using the default locale '". DEFAULT_LOCALE ."'.</p>\n";
  56. }
  57. ?>
  58. <hr />
  59. <?php
  60. // using PHP-gettext
  61. print "<pre>";
  62. print _("This is how the story goes.\n\n");
  63. for ($number=6; $number>=0; $number--) {
  64. print sprintf(T_ngettext("%d pig went to the market\n",
  65. "%d pigs went to the market\n", $number),
  66. $number );
  67. }
  68. print "</pre>\n";
  69. ?>
  70. <hr />
  71. <p>&laquo; <a href="./">back</a></p>
  72. </body>
  73. </html>