用PHP做语言文件的最有效方法? [英] Most efficient way to do language file in PHP?

查看:95
本文介绍了用PHP做语言文件的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题已更新,而不是提出新问题...

我真的想在我建立的社交网站上提供除英语以外的其他几种替代语言,这将是我第一次进行任何类型的语言翻译,所以请耐心等待.
我正在研究,所以我一直都乐于接受并接受各种想法,这里已经有很多问题了.

I really want to provide a few alternative languages other then English on my social network site I am building, this will be my first time doing any kind of language translation so please bear with me.
I am researching so I am al ear and open to ideas and I have a lot already here is are the questions.

1)
i18n是什么意思,我在研究SO语言翻译时经常看到它吗?

1)
What does i18n mean, I see it often when researching language translation on SO?

2)
大多数人说使用 gettext PHP对其进行了扩展或支持,
好吧,我一直在研究它,并且对它有基本的了解,据我所知,走这条路还需要做很多工作,
我的意思是对网站进行编码以使用其功能,即; _('hello world,我现在在英语中'),否则 gettext('hello world,我现在在英语中')没问题,因为任何路线我去需要.
但是随后您必须在服务器上安装gettext并使其正常运行,
然后使用一些特殊的编辑器来创建特殊的文件并对其进行编译,我认为呢?

2)
Most people say use gettext PHP has an extension or support for it,
well I have been researching it and I have a basic understanding of it, as far as I can tell it is a lot of extra work to go this route,
I mean coding my site to use it's functions ie; _('hello world i'm in English for now') or else gettext('hello world i'm in English for now') is no problem as any route I go will require that.
But then you have to install gettext on your server and get it working,
then use some special editors to create special files and compile them I think?

听起来像是一种痛苦,但我知道这应该是最好的选择,每个人似乎都说是这样.
那么有人可以告诉我为什么要走这条路吗?

Sounds like a pain, I understand this is supposed to be the best route to go though, well everyone seems to say it is.
So can someone tell me why this is the route to go?

3)
我真的很喜欢这种方法的简单性,只是构建一个语言数组并在下面的示例中的函数中调用所需的短语 ,则只需包含一个具有适当语言数组的文件.

3)
I really like the simplicity of this approach, just building a language array and calling the phrase you need in a function like the example below , you would then just include a file with the appropriate language array.

我真正想知道的是,与使用gettext相比,这是在高流量和相当大的站点上性能较差的方法吗?如果可以的话,您能解释一下为什么吗?

What I really want to know is, would this be the less better performance method on a high traffic and fairly large site compared to using gettext and if so can you explain why please?

<?PHP
//Have seperate language files for each language I add, this would be english file
function lang($phrase){
    static $lang = array(
        'NO_PHOTO' => 'No photo\'s available',
        'NEW_MEMBER' => 'This user is new'
    );
    return $lang[$phrase];
}
//Then in application where there is text from the site and not from users I would do something like this
echo lang('NO_PHOTO');  // No photo's available would show here
?>

*下面的brianreavis答案中使用的一些代码

* some code used from brianreavis's answer below

推荐答案

不要重新发明轮子.例如,使用 gettext

Don't reinvent the wheel. Use for example gettext or Zend_Translate.

这篇关于用PHP做语言文件的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆