b50f752fb3ab4aa43c73513d40ef02d04b8b8ec8
[scuttle] / includes / php-gettext / examples / pigs_fallback.php
1 <?php
2 /*
3    Copyright (c) 2003,2004,2005 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 // define constants
25 define(PROJECT_DIR, realpath('./'));
26 define(LOCALE_DIR, PROJECT_DIR .'/locale');
27 define(DEFAULT_LOCALE, 'en_US');
28
29 require_once('../gettext.inc');
30
31 $supported_locales = array('en_US', 'sr_CS', 'de_CH');
32 $encoding = 'UTF-8';
33
34 $locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;
35
36 // gettext setup
37 T_setlocale(LC_MESSAGES, $locale);
38 // Set the text domain as 'messages'
39 $domain = 'messages';
40 T_bindtextdomain($domain, LOCALE_DIR);
41 T_bind_textdomain_codeset($domain, $encoding);
42 T_textdomain($domain);
43
44 header("Content-type: text/html; charset=$encoding");
45 ?>
46 <html>
47 <head>
48 <title>PHP-gettext fallback example</title>
49 </head>
50 <body>
51 <h1>PHP-gettext as a fallback solution</h1>
52 <p>Example showing how to use PHP-gettext as a fallback solution if the native gettext library is not available or the system does not support the requested locale.</p>
53
54 <?php
55 print "<p>";
56 foreach($supported_locales as $l) {
57         print "[<a href=\"?lang=$l\">$l</a>] ";
58 }
59 print "</p>\n";
60
61 if (!locale_emulation()) {
62         print "<p>locale '$locale' is supported by your system, using native gettext implementation.</p>\n";
63 }
64 else {
65         print "<p>locale '$locale' is <strong>not</strong> supported on your system, using custom gettext implementation.</p>\n";
66 }
67 ?>
68
69 <hr />
70
71 <?php
72 // using PHP-gettext
73 print "<pre>";
74 print T_("This is how the story goes.\n\n");
75 for ($number=6; $number>=0; $number--) {
76   print sprintf( T_ngettext("%d pig went to the market\n", 
77                           "%d pigs went to the market\n", $number), 
78                  $number );
79 }
80 print "</pre>\n";
81 ?>
82
83 <hr />
84 <p>&laquo; <a href="./">back</a></p>
85 </body>
86 </html>

Benjamin Mako Hill || Want to submit a patch?