开发者

PHP - Language Data

开发者 https://www.devze.com 2022-12-31 19:41 出处:网络
What\'s the best way to store language data? Keep it as variables in some kind of lang.php file... 开发者_运维知识库

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.


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)...


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

0

精彩评论

暂无评论...
验证码 换一张
取 消