Denis Bobrovnikov
Denis Bobrovnikov

Reputation: 630

PHP - Language Data

What's the best way to store language data?


Keep it as variables in some kind of lang.php file...

$l_ipsum = 'smth';

$l_rand = 'string';


Or select them from a database? I'm in search of your advice.

Upvotes: 1

Views: 71

Answers (2)

zzz
zzz

Reputation: 87

Here is a list of a Zend_Translate adapters to give you idea of how it could look like

http://framework.zend.com/manual/en/zend.translate.adapter.html

Upvotes: 0

ircmaxell
ircmaxell

Reputation: 165201

Keep them in an array, so you don't pollute the global namespace.

    $lang = array(
        'ipsum' => 'smth',
        'rand' => 'string',
    );

Plus, you can create a helper function to get the string

    function translate($string) {
        global $lang;
        return isset($lang[$string]) ? $lang[$string] : $string;
    }

Of course, there are a thousand ways to do this (and I personally wouldn't use global variables, but it's all up to your skill level and personal preferences)...

Upvotes: 1

Related Questions