【发布时间】:2010-12-30 18:39:43
【问题描述】:
我正在做一个 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];
}
}
【问题讨论】:
-
如果您可以使用 gettext(您应该这样做),请查看 PHP-I18N 以获得完整的介绍和帮助类。
标签: php internationalization translation