我正在做一个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)