【问题标题】:PoEdit .PO generation errorPoEdit .PO 生成错误
【发布时间】:2011-11-20 14:12:11
【问题描述】:

我已尝试将所有_('gettext') 函数调用扫描到新的 PoEdit 目录中。解析文件后显示此错误:

Filename.class.php:11: warning: Although being used in a format string position, the msgid is not a valid PHP format string. Reason: In the directive number 1, the character '"' is not a valid conversion specifier.

文件名.class.php,第 11 行如下所示:

throw new fatalException(sprintf(_('The chosen directory "%" does not exist.'), $dir));

.MO 文件仍会生成,但网站上未显示翻译文本。而是显示对 _('gettext') 的调用中的原始文本。这可能是问题所在,还是有其他原因(例如不正确的setlocale() 信息)导致翻译不起作用?有人能告诉我上面的错误信息是什么意思吗?

在我的本地主机上使用 PHP 5.3.8 和 Apache 2.2.17 在 WAMP Server 2.1 上运行 Windows。

谢谢。

【问题讨论】:

    标签: php wamp gettext poedit po


    【解决方案1】:

    我怎么会错过这个......

    异常消息在% 之后没有s,因此它采用双引号作为转换说明符...

    将问题文件的第 11 行替换为以下代码解决了问题。

    throw new fatalException(sprintf(_('The chosen directory "%s" does not exist.'), $dir));

    我仍然无法显示翻译后的文本,因此问题似乎出在其他地方。稍后我可能会发布另一个关于此的问题...

    【讨论】:

    • 既然 msgid 已更改,您是否更新了 .po、.mo 并重新启动了 Web 服务器?
    • @dsas 是的,一切都已完成。生成文件/重启 Apache 时没有报错。
    • 我还检查了我的 setlocale() 函数,它没有返回 false。 Gettext 扩展已启用...
    【解决方案2】:

    另外,也许你应该在引号前加一个反斜杠来转义它们?

    【讨论】:

      猜你喜欢
      • 2016-12-21
      • 2013-05-09
      • 1970-01-01
      • 2021-07-11
      • 2011-01-31
      • 2017-08-01
      • 2015-07-04
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多