note 25871 deleted from language.constants by nlopess
| From: | nlopess@php.net | Date: | Wed, 24 Mar 2004 14:52:13 +0000 |
| Subject: | note 25871 deleted from language.constants by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67096@lists.php.net to get a copy of this message | ||
Note Submitter: fmmarzoa@gmx.net
----
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.