Tagged 0.7.5
[scuttle] / includes / php-gettext / examples / pigs_dropin.php
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
6    This file is part of PHP-gettext.
7
8    PHP-gettext 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    PHP-gettext 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 PHP-gettext; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
22 */
23
24 error_reporting(E_ALL | E_STRICT);
25
26 // define constants
27 define('PROJECT_DIR', realpath('./'));
28 define('LOCALE_DIR', PROJECT_DIR .'/locale');
29 define('DEFAULT_LOCALE', 'en_US');
30
31 require_once('../gettext.inc');
32
33 $supported_locales = array('en_US', 'sr_CS', 'de_CH');
34 $encoding = 'UTF-8';
35
36 $locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;
37
38 // gettext setup
39 T_setlocale(LC_MESSAGES, $locale);
40 // Set the text domain as 'messages'
41 $domain = 'messages';
42 bindtextdomain($domain, LOCALE_DIR);
43 // bind_textdomain_codeset is supported only in PHP 4.2.0+
44 if (function_exists('bind_textdomain_codeset')) 
45   bind_textdomain_codeset($domain, $encoding);
46 textdomain($domain);
47
48 header("Content-type: text/html; charset=$encoding");
49 ?>
50 <html>
51 <head>
52 <title>PHP-gettext dropin example</title>
53 </head>
54 <body>
55 <h1>PHP-gettext as a dropin replacement</h1>
56 <p>Example showing how to use PHP-gettext as a dropin replacement for the native gettext library.</p>
57 <?php
58 print "<p>";
59 foreach($supported_locales as $l) {
60         print "[<a href=\"?lang=$l\">$l</a>] ";
61 }
62 print "</p>\n";
63
64 if (!locale_emulation()) {
65         print "<p>locale '$locale' is supported by your system, using native gettext implementation.</p>\n";
66 }
67 else {
68         print "<p>locale '$locale' is _not_ supported on your system, using the default locale '". DEFAULT_LOCALE ."'.</p>\n";
69 }
70 ?>
71
72 <hr />
73
74 <?php
75 // using PHP-gettext
76 print "<pre>";
77 print _("This is how the story goes.\n\n");
78 for ($number=6; $number>=0; $number--) {
79   print sprintf(T_ngettext("%d pig went to the market\n", 
80                           "%d pigs went to the market\n", $number), 
81                  $number );
82 }
83 print "</pre>\n";
84 ?>
85
86 <hr />
87 <p>&laquo; <a href="./">back</a></p>
88 </body>
89 </html>

Benjamin Mako Hill || Want to submit a patch?