note 99983 deleted from book.gettext by danbrown

From: Date: Fri, 17 Sep 2010 20:16:38 +0000
Subject: note 99983 deleted from book.gettext by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172703@lists.php.net to get a copy of this message
Note Submitter: c9s cornelius dot howl at gmail dot com ---- I wrote a simple i18n class for this: http://github.com/c9s/i18n.php <?php class I18N { protected $cur_lang = array(); protected $a_langs = array(); function init( $force_lang = null ) { $lang = null; if( $force_lang ) { $lang = $force_lang; } else if( @$_REQUEST['lang'] ) { $lang = $_REQUEST['lang']; } else if( isset( $_COOKIE['lang'] ) ) { $lang = $_COOKIE['lang']; } if( ! $lang ) { $lang = DEF_LANG; } $this->speak( $lang ); } // set current language function speak( $lang ) { $this->cur_lang = $lang; setcookie("lang", $lang , 0 ); } function is_speaking() { return $this->cur_lang; } // get available language list function langs() { return $this->a_langs; } function set_list( $list ) { $this->a_langs = $list; } function add( $lang , $name ) { $this->a_langs[ $lang ] = $name; } function remove( $lang ) { unset( $this->a_langs[ $lang ] ); } // get language name from language hash function name( $lang ) { return @$this->a_langs[ $lang ]; } function gettext( $textdomain , $localdir = null ) { $lang = $this->cur_lang; putenv("LANG=$lang"); setlocale(LC_MESSAGES, $lang ); if( $localdir == null ) $localdir = dirname(__FILE__) . '/' . 'locale'; bindtextdomain( $textdomain, $localdir ); bind_textdomain_codeset( $textdomain, 'UTF-8'); textdomain( $textdomain ); } } function i18n() { global $i18n; if( $i18n == null ) { $i18n = new I18N(); init_i18n( $i18n ); } return $i18n; } ?>

« previous php.notes (#172703) next »