note 89076 modified in function.setlocale by danbrown

From: Date: Mon, 23 Feb 2009 00:53:19 +0000
Subject: note 89076 modified in function.setlocale by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150991@lists.php.net to get a copy of this message
Pay attention to the syntax. - UTF8 without dash ('-') - locale.codeset and not locale-codeset. Stupid newbie error but worth knowing them when starting with gettext. <?php $codeset = "UTF8"; // warning ! not UTF-8 with dash '-' // for windows compatibility (e.g. xampp) : theses 3 lines are useless for linux systems putenv('LANG='.$lang.'.'.$codeset); putenv('LANGUAGE='.$lang.'.'.$codeset); bind_textdomain_codeset('mydomain', $codeset); // set locale bindtextdomain('mydomain', ABSPATH.'/locale/'); setlocale(LC_ALL, $lang.'.'.$codeset); textdomain('mydomain'); ?> where directory structure of locale is (for example) : locale/fr_FR/LC_MESSAGES/mydomain.mo locale/en_US/LC_MESSAGES/mydomain.mo and ABSPATH is the absolute path to the locale dir further note, under linux systems, it seems to be necessary to create the locale at os level using 'locale-gen'. --was-- Pay attention to the syntax. - UTF8 without dash ('-') - locale.codeset and not locale-codeset. Stupid newbie error but worth knowing them when starting with gettext. $codeset = "UTF8"; // warning ! not UTF-8 with dash '-' // for windows compatibility (e.g. xampp) : theses 3 lines are useless for linux systems putenv('LANG='.$lang.'.'.$codeset); putenv('LANGUAGE='.$lang.'.'.$codeset); bind_textdomain_codeset('mydomain', $codeset); // set locale bindtextdomain('mydomain', ABSPATH.'/locale/'); setlocale(LC_ALL, $lang.'.'.$codeset); textdomain('mydomain'); where directory structure of locale is (for example) : locale/fr_FR/LC_MESSAGES/mydomain.mo locale/en_US/LC_MESSAGES/mydomain.mo and ABSPATH is the absolute path to the locale dir further note, under linux systems, it seems to be necessary to create the locale at os level using 'locale-gen'. http://php.net/manual/en/function.setlocale.php

« previous php.notes (#150991) next »