小编San*_*dro的帖子

PHP简单的翻译方法 - 您的意见

我正在做一个PHP网站,没有使用任何框架.我需要该网站有多种语言版本,我正在阅读它,它似乎有点令人困惑.有几种解决方案,但似乎都依赖于特定的框架.

您如何看待使用如下所示的简单翻译功能?

我的意思是,我想知道使用这些代码有什么不利之处.这是(这只是一个简单而不完整的样本):

class Translator{

    private $translations;

    public function __construct(){
        $this->translations = array(
            'Inbox'  => array(
                'en' => 'Inbox',
                'fr' => 'the french word for this'
            ),
            'Messages' => array(
                'en' => 'Messages',
                'fr' => 'the french word for this'
            )
            //And so on...
        );
    }

    public function translate($word,$lang){
        echo $this->translations[$word][$lang];
    }
}
Run Code Online (Sandbox Code Playgroud)

php translation internationalization

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

internationalization ×1

php ×1

translation ×1