Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // define constants
- define('PROJECT_DIR', realpath('./'));
- define('LOCALE_DIR', PROJECT_DIR .'/locales');
- define('DEFAULT_LOCALE', 'fr_FR');
- require_once('../libs/php-gettext-1.0.11/gettext.inc');
- $supported_locales = array('fr_FR', 'en_US', 'fr_FR.utf8', 'en_US.utf8');
- // Set cookie to keep track of the active language
- if (isset($_GET['lang'])) {
- // Langage is passed through URL parameters
- $lang = $_GET['lang'];
- setcookie('lang', $lang, time() + 3600*24, '/'); // Expires in 24h
- }
- elseif (isset($_COOKIE['lang']))
- $lang = $_COOKIE['lang'];
- if (!isset($lang)) {
- // Use browser's locale
- $lang = substr($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'], 0, 2);
- if (!isset($lang) || !in_array($lang, $supported_locales)) // Default locale
- $lang = DEFAULT_LOCALE;
- //echo "isset($lang) " + $lang;
- setcookie('lang', $lang, time() + 3600*24, '/'); // Expires in 24h
- }
- $encoding = 'UTF-8';
- $locale = $lang;
- // gettext setup
- T_setlocale(LC_MESSAGES, $locale);
- // Set the text domain as 'translation'
- $domain = 'translation';
- bindtextdomain($domain, LOCALE_DIR);
- // bind_textdomain_codeset is supported only in PHP 4.2.0+
- if (function_exists('bind_textdomain_codeset'))
- bind_textdomain_codeset($domain, $encoding);
- textdomain($domain);
- header("Content-type: text/html; charset=$encoding");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement