Am I breaking any “php good practice” in the following php array which deals with 3 (human) languages?

后端 未结 6 1661
执笔经年
执笔经年 2021-01-03 10:47

This is the most optimal way of dealing with a multilingual website I can think of, right now (not sure) which doesn\'t involve gettext, zend_translate or any php plugin or

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 11:23

    It's OK generally. For instance, punBB's localization works this way. It is very fast. Faster than calling a function or an object's method or property. But I see a problem with this approach, since it doesn't support language fallbacks easily. I mean, if you don't have a string for Chinese, let it be displayed in English.

    This problem is topical when you upgrade your system and you don't have time to translate everything in every language.

    I'd better use something like

    lang.en.php

    $langs['en'] = array(
        ...
    );
    

    lang.cn.php

    $langs['cn'] = array(
        ...
    );
    

    [prepend].php (some common lib)

    define('DEFAULT_LANG', 'en');
    include_once('lang.' . DEFAULT_LANG '.php');
    include_once('lang.' . $user->lang . '.php');
    $lang = array_merge($langs[DEFAULT_LANG], $langs[$user->lang]);
    

提交回复
热议问题