7

我正在使用 gettext() 来翻译我网站上的一些文本。这些大多是短文本/按钮,如“返回”、“名称”、...

// I18N support information here
$language = "en_US";
putenv("LANG=$language");
setlocale(LC_ALL, $language);


// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, "/opt/www/abc/web/www/lcl");
textdomain($domain);

echo gettext("Back");

我的问题是,这个文本(id)在 echo gettext("") 部分中可以有多长?

是否会减慢长文本的处理速度?或者它也可以正常工作?像这样的例子:

echo _("LZ adfadffs is a VVV contributor who writes a weekly column for Cv00m. The former Hechinger Institute Fellow has had his commentary recognized by the Online News Association, the National Association of Black Journalists and the National ");
4

3 回答 3

6

官方的gettext 文档只有这个建议:

可翻译的字符串应限于一个段落;不要让一条消息超过十行。原因是当可翻译字符串发生变化时,翻译者面临着更新整个翻译字符串的任务。也许英文字符串中只有一个单词会发生变化,但翻译者看不到(使用当前的翻译工具),因此她必须校对整个消息。

字符串的长度没有官方的限制,它们显然至少可以超过“一个段落/10 行”。

对于长字符串,实际上应该没有可测量的性能损失。

于 2013-08-14T10:24:41.177 回答
1

gettext 实际上对字符串的长度有4096 个字符的限制。

当您超过此限制时,您会收到警告:

Warning: gettext(): msgid passed too long in %s on line %d

并返回你bool(false)而不是文本。

来源: PHP 解释器存储库 - gettext 溢出错误的真正修复

于 2018-02-23T13:32:08.370 回答
0

函数gettext http://www.php.net/manual/en/function.gettext.php

它被定义为字符串输入,因此您的机器内存将成为限制因素。

如果您的开发机器上有它,请尝试使用 microtime 或更好的 xdebug 对其进行基准测试。

于 2013-08-14T10:22:56.267 回答