Search code examples
phpcode-separation

PHP: Where should I store the text for info & warning messages


I have a question concerning the design of my project's Code. In most cases, it is important to separate content from code (HTML mixed with PHP in bigger apps=No good idea, etc.) but how should I handle things like the text of error messages?

Assuming this one message will be only used in one case/PHP file:

MessageBox( 'Something gone wrong, probably your fault' );

or

MessageBox( Lang::error_usersfault );

(Where Lang is a class located in some config file, full of consts)

  • If you have any experiences (I think every PHP programmer will come across something like this) with things like in the example above - What are they? How do you solve it?

  • What is the better solution?


Solution

  • May be you'll find php extension gettext useful?

    MessageBox(_("Have a nice day"));
    

    PHP Manual of Gettext::gettext