Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to set locale choice as cookie for "gettext "

Status
Not open for further replies.

jacksondorado

IS-IT--Management
Apr 12, 2001
135
US
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>";
?>
 
use a session variable instead. not a cookie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top