note 58310 added to function.gettext

From: Date: Mon, 31 Oct 2005 09:38:23 +0000
Subject: note 58310 added to function.gettext
Groups: php.notes 
Request: Send a blank email to php-notes+get-97869@lists.php.net to get a copy of this message
Gettext translations are cached. If you change *.mo files your page may not be translated as expected. Here's simple workaround which does not require restarting webserver (I know, this is just a dirty hack): <?php function initialize_i18n($locale) { putenv('LANG='.$locale); setlocale(LC_ALL,""); setlocale(LC_MESSAGES,$locale); setlocale(LC_CTYPE,$locale); $domains = glob($locales_root.'/'.$locale.'/LC_MESSAGES/messages-*.mo'); $current = basename($domains[0],'.mo'); $timestamp = preg_replace('{messages-}i','',$current); bindtextdomain($current,$locales_root); textdomain($current); } ?> to make this work you have to put your locale inside file messages-[unix_time].mo and use this name (without .mo) as your domain to fool caching mechanism (domain names differ) msgfmt messages.po -o messages-date +%s.mo for me this works fine (although this is not very elegant solution) ---- Manual Page -- http://www.php.net/manual/en/function.gettext.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58310 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58310&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58310&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58310&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58310&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58310&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58310&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58310&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58310&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97869) next »