3 Copyright (c) 2003,2004,2005,2009 Danilo Segan <danilo@kvota.net>.
4 Copyright (c) 2005,2006 Steven Armstrong <sa@c-area.ch>
6 This file is part of PHP-gettext.
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.
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.
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
24 error_reporting(E_ALL | E_STRICT);
27 define('PROJECT_DIR', realpath('./'));
28 define('LOCALE_DIR', PROJECT_DIR .'/locale');
29 define('DEFAULT_LOCALE', 'en_US');
31 require_once('../gettext.inc');
33 $supported_locales = array('en_US', 'sr_CS', 'de_CH');
36 $locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;
39 T_setlocale(LC_MESSAGES, $locale);
40 // Set the text domain as 'messages'
42 T_bindtextdomain($domain, LOCALE_DIR);
43 T_bind_textdomain_codeset($domain, $encoding);
44 T_textdomain($domain);
46 header("Content-type: text/html; charset=$encoding");
50 <title>PHP-gettext fallback example</title>
53 <h1>PHP-gettext as a fallback solution</h1>
54 <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>
58 foreach($supported_locales as $l) {
59 print "[<a href=\"?lang=$l\">$l</a>] ";
63 if (!locale_emulation()) {
64 print "<p>locale '$locale' is supported by your system, using native gettext implementation.</p>\n";
67 print "<p>locale '$locale' is <strong>not</strong> supported on your system, using custom gettext implementation.</p>\n";
76 print T_("This is how the story goes.\n\n");
77 for ($number=6; $number>=0; $number--) {
78 print sprintf( T_ngettext("%d pig went to the market\n",
79 "%d pigs went to the market\n", $number),
86 <p>« <a href="./">back</a></p>