note 69308 added to function.bind-textdomain-codeset

From: Date: Thu, 31 Aug 2006 07:58:04 +0000
Subject: note 69308 added to function.bind-textdomain-codeset
Groups: php.notes 
Request: Send a blank email to php-notes+get-116530@lists.php.net to get a copy of this message
So, by using this function and by setting the LANGUAGE variable, you should be able to have a functioning i18n system that is not dependent upon a system's locale installation. Here is a sample from a method I created for a language class. Look for it on http://wiki.creativecommons.org/Developer soon: function Init () { // set the LANGUAGE environmental variable // This one for some reason makes a difference FU@#$%^&*!CK // and when combined with bind_textdomain_codeset allows one // to set locale independent of server locale setup!!! if ( false == putenv("LANGUAGE=" . $this->_language ) ) CCDebug::Log(sprintf("Could not set the ENV variable LANGUAGE = %s", $this->_language)); // set the LANG environmental variable if ( false == putenv("LANG=" . $this->_language ) ) CCDebug::Log(sprintf("Could not set the ENV variable LANG = %s", $this->_language)); // if locales are not installed in locale folder, they will not // get set! This is usually in /usr/lib/locale // Also, the backup language should always be the default language // because of this...see the NOTE in the class description // Try first what we want but with the .utf8, which is what the locale // setting on most systems want (and is most compatible // Then just try the standard lang encoding asked for, and then if // all else fails, just try the default language // LC_ALL is said to be used, but it has nasty usage in some languages // in swapping commas and periods! Thus try LC_MESSAGE if on one of // those systems. // It is supposedly not defined on WINDOWS, so am including it here // for possible uncommenting if a problem is shown // // if (!defined('LC_MESSAGES')) define('LC_MESSAGES', 6); // yes, setlocale is case-sensitive...arg $locale_set = setlocale(LC_ALL, $this->_language . ".utf8", $this->_language . ".UTF8", $this->_language . ".utf-8", $this->_language . ".UTF-8", $this->_language, CC_LANG); // if we don't get the setting we want, make sure to complain! if ( ( $locale_set != $this->_language && CC_LANG == $locale_set) || empty($locale_set) ) { CCDebug::Log( sprintf("Tried: setlocale to '%s', but could only set to '%s'.", $this->_language, $locale_set) ); } $bindtextdomain_set = bindtextdomain($this->_domain, CC_LANG_LOCALE . "/" . $this->_locale_pref ); if ( empty($bindtextdomain_set) ) CCDebug::Log( sprintf("Tried: bindtextdomain, '%s', to directory, '%s', " . "but received '%s'", $this->_domain, CC_LANG_LOCALE . "/" . $this->_locale_pref, $bindtextdomain_set) ); bind_textdomain_codeset($this->_domain, "UTF-8"); $textdomain_set = textdomain($this->_domain); if ( empty($textdomain_set) ) CCDebug::Log(sprintf("Tried: set textdomain to '%s', but got '%s'", $this->_domain, $textdomain_set)); } // end of method Init () ---- Server IP: 64.71.164.2 Probable Submitter: 64.121.195.22 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.bind-textdomain-codeset.php Edit -- https://master.php.net/note/edit/69308 Del: integrated -- https://master.php.net/note/delete/69308/integrated Del: useless -- https://master.php.net/note/delete/69308/useless Del: bad code -- https://master.php.net/note/delete/69308/bad+code Del: spam -- https://master.php.net/note/delete/69308/spam Del: non-english -- https://master.php.net/note/delete/69308/non-english Del: in docs -- https://master.php.net/note/delete/69308/in+docs Del: other reasons-- https://master.php.net/note/delete/69308 Reject -- https://master.php.net/note/reject/69308 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116530) next »