使用PHP的gettext扩展VS在多语种网站PHP数组? [英] Using PHP Gettext Extension vs PHP Arrays in Multilingual Websites?

查看:166
本文介绍了使用PHP的gettext扩展VS在多语种网站PHP数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经看到关于使用数组的gettext的,而不是只有2个好东西,是我没有创造的问候语子阵列(或任何其所谓)。而且我没有为默认语言创建一个文件夹。

So far the only 2 good things that I've seen about using gettext instead of arrays is that I don't have to create the "greeting" "sub-array" (or whatever its called). And I don't have to create a folder for the "default language".

有没有使用gettext和PHP数组的多语种网站的其他优点和COS?

Are there other pros and cos of using gettext and php arrays for multilingual websites?

同时使用gettext:

西班牙/ messages.po:

#: test.php:3
msgid "Hello World!"
msgstr "Hola Mundo"

的index.php:

<?php echo _("Hello World!"); ?>

的index.php LANG =西班牙语:

<?php echo _("Hello World!"); ?> turns to Hola Mundo

使用PHP数组:

lang.en.php

<?php
$lang = array(
    "greeting" => "Hello World",
);
?>

lang.es.php

<?php
$lang = array(
    "greeting" => "Hola Mundo",
);
?>

的index.php:

<?php echo $lang['greeting']; ?> greeting turns to Hello World

的index.php?LANG =西班牙

<?php echo $lang['greeting']; ?> greeting turns to Hola Mundo

(我第一次开始与gettext的,但它不是我的免费共享托管Zymic支持。我不想用了Zend_Framework,我发现它太复杂,我简单的任务,所以我终于结束了使用PHP 定义,但后来有人告诉我,我应该使用数组)

(I first started with gettext, but it wasn't supported in my shared free hosting Zymic. I didn't want to use Zend_translate, I found it too complicated to my simple task, so I finally ended up using php define, but later on someone told me I should use arrays)

推荐答案

利用GNU的gettext你得到的占位符支持像printf和国际复数形式。为了占位符可以翻译改变或跳过。

Using GNU gettext you get support for placeholders like with printf and international plural forms. Placeholders order can be changed in translation or skipped.

从PHP文件示例:


<?php
setlocale(LC_ALL, 'cs_CZ');
printf(ngettext("%d window", "%d windows", 1), 1); // gives "1 okno"
printf(ngettext("%d window", "%d windows", 2), 2); // gives "2 okna"
printf(ngettext("%d window", "%d windows", 5), 5); // gives "5 oke"
?>

另一个亲的是,你可以使用标准工具进行术语管理,翻译记忆库和机器翻译@middus如指出。

Another pro is that you can use standard tools for terminology management, translations memory and machine translation as pointed by @middus.

有关共享环境中有来自达尼洛Segan一个伟大的 PHP-gettext库

For shared environments there is a great php-gettext library from Danilo Segan.

这篇关于使用PHP的gettext扩展VS在多语种网站PHP数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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