语言文件的gettext有什么好处? [英] What is so good about gettext for language files?

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

问题描述

在用PHP制作多语言应用程序时,到处都是,每个人都说 gettext 是最好的方法.我只是想知道为什么?

Everywhere on SO when it comes to making a multi language app in PHP everyone say that gettext is the best way to do it. I am just wanting to know why?

像是什么使下面的方法比使用gettext效率低?

Like what makes this method below, less efficient then using gettext?

<?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
?>

推荐答案

gettext的优点是它实际上是一种标准:它被许多应用程序使用,使用多种语言,这意味着很多人们使用它.

A good thing with gettext is that it is kind of a de-facto standard : it is used by lots of applications, in many languages -- which means many people work with it.

(实际上可能是结果或原因,或两者都有)的另一个好处是,有几种工具,例如 Poedit 来编辑gettext文件:您不必浏览某​​些PHP (或其他任何东西)源代码.这是非常重要的:

Another good thing (maybe a consequence, or a cause, or both, actually) is that several tools, like Poedit for instance, exist to edit gettext files : you don't have to go through some PHP (or whatever) source-code. And this is very important :

  • 这意味着非技术人员可以编辑gettext本地化文件
    • 也许这对您现在似乎并不重要
    • 但是,如果您正在开发大型开源应用程序,那么成功就变得很重要,并且很多人都需要用自己的语言来编写它.
    • it means non-technical people can edit gettext localisation files
      • maybe this doesn't seem important to you now,
      • but if you are working on a big open-source application, it'll become important if it is successful and many people need it in their own language.

      这篇关于语言文件的gettext有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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