PHP string literal file ... good practice?

I am trying to create a string literal file for PHP, so I can store all my strings in a single file.

I was wondering if it would be good practice to do something like:

class Literals
{
    const String1 = "Hello";
    const String2 = "World!";
    //... (up to 100+ literals)...
}

And then somewhere in my code I could call it like this:

$hello = Literals::String1;

Is this a good practice?

+3
source share
2 answers

It depends on what you are going to do with the strings. If you are going to display them to the user, then of course this is an easy way to internationalize, although you need to look at something more advanced if you are going to do it. If you are just going to use them for associative array keys, database column names or other internal things, then no, just keep them strict.

+3

, String1... StringN:)

( Apple):

- :

<h1><?php localize("Homepage","String for the homepage") ?></h1>

.

function localize($key,$help='') {
   //do a lookup of the key and if not found use the key itself
}

, :

$strings = array(
 /** String for the homepage */
 'Homepage' => 'Homepage'
);

, , . , , .

+1

All Articles