jacksondorado
IS-IT--Management
I am using gettext to translate a static PHP website. The user can click on the language they choose, but the locale does not persist once they leave that page.
I'm not sure the best way to set a cookie with the chosen locale, and reset the default locale to use the chosen one. Any help pointing in the right direction is much appreciated.
The gettext example goes like this:
####header
<?php
// define constants
define('PROJECT_DIR', realpath('./'));
define('LOCALE_DIR', PROJECT_DIR .'/locale');
define('DEFAULT_LOCALE', 'en_US');
require_once('gettext.inc');
$supported_locales = array('en_US', 'es_MX');
$encoding = 'UTF-8';
$locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;
// gettext setup
T_setlocale('LC_ALL', $locale);
// Set the text domain as 'messages'
$domain = 'messages';
T_bindtextdomain($domain, LOCALE_DIR);
T_bind_textdomain_codeset($domain, $encoding);
T_textdomain($domain);
?>
#####body
<?php
print "<p>";
foreach($supported_locales as $l) {
print "[ <a href=\"?lang=$l\">$l</a> ]";
}
print "</p>";
?>
I'm not sure the best way to set a cookie with the chosen locale, and reset the default locale to use the chosen one. Any help pointing in the right direction is much appreciated.
The gettext example goes like this:
####header
<?php
// define constants
define('PROJECT_DIR', realpath('./'));
define('LOCALE_DIR', PROJECT_DIR .'/locale');
define('DEFAULT_LOCALE', 'en_US');
require_once('gettext.inc');
$supported_locales = array('en_US', 'es_MX');
$encoding = 'UTF-8';
$locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;
// gettext setup
T_setlocale('LC_ALL', $locale);
// Set the text domain as 'messages'
$domain = 'messages';
T_bindtextdomain($domain, LOCALE_DIR);
T_bind_textdomain_codeset($domain, $encoding);
T_textdomain($domain);
?>
#####body
<?php
print "<p>";
foreach($supported_locales as $l) {
print "[ <a href=\"?lang=$l\">$l</a> ]";
}
print "</p>";
?>