note 25871 added to language.constants
| From: | fmmarzoa at gmx dot net | Date: | Wed, 09 Oct 2002 15:38:48 +0000 |
| Subject: | note 25871 added to language.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37851@lists.php.net to get a copy of this message | ||
Constants can be useful for i18n and l10n (internationalization and localization). I'm using a
module for each language my application supports for string isolation. Each module only contains
constants definitions. In example, I've this in my module 'en.php' (English):
define (strSayHello, 'Hello!');
While in my module 'es.php' (Spanish), I've the constant redefined:
define (strSayHello, '¡Hola!');
The language module needed is dinamically choosen by the application based on user preferences.
All works ok, but I've had a trouble with constants that must include variable values, in
example, I've something like:
define (strArticleDescr, 'Published by $article_author on $article_date in
$article_lang_name');
Now, when I try to use this, the value is interpreted literally, so:
print strArticleDescr;
Will show:
Published by $article_author on $article_date in $article_lang_name
I've found a solution for this using 'eval' for parsing the constant, thats:
eval ('print "'.strArticleDescr.'";')
And now things works ok, like in example:
Published by Francisco M. Marzoa on 2002-10-09 15:39:10 in Spanish
Hope you find this useful.
--
http://www.php.net/manual/en/language.constants.php
http://master.php.net/manage/user-notes.php?action=edit+25871
http://master.php.net/manage/user-notes.php?action=delete+25871
http://master.php.net/manage/user-notes.php?action=reject+25871