dotdx80642
2012-09-21 14:26
浏览 73
已采纳

PHP gettext找不到任何转换的日志字符串

I have a website that is internationalized using php's built-in Gettext / PO support

echo _("string to be translated");

The site being in beta, there are certainly some strings that don't get translated. To help debugging, is there a way to log gettext errors, i.e. log strings for which PO has not found any matching entry in the PO file?

图片转代码服务由CSDN问答提供 功能建议

我有一个使用php内置的Gettext / PO支持进行国际化的网站

echo _(“要翻译的字符串”);

网站处于测试阶段,肯定会有一些字符串无法翻译。 为了帮助调试,有没有办法记录gettext错误,即PO在PO文件中找不到任何匹配条目的日志字符串?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dpojoxa5613 2012-12-30 15:09
    已采纳

    The problem with what you want to do is that you'll only find untranslated strings at runtime, and only for code paths which are actually executed. It may take years for you to find all strings, and in the meantime you have to look at your log files regularly and sync your updated translations with what's happening in the log file. That's not a deterministic approach to translations.

    If you're using gettext, you need to establish a workflow that's appropriate for it. And the gettext workflow and toolchain are pretty well thought out and time tested.

    1. Prepare your source code by wrapping strings in gettext functions.
    2. Extract the prepared strings into POT files, typically using xgettext but possibly using a custom parser/extractor and a library like Kunststube\POTools (shameless self promotion).
    3. Create PO files from the extracted template files using msginit.
    4. Translate the PO files.
    5. Keep updated source/POT files in sync with PO files using msgmerge.
    6. Compile PO files to MO files using msgfmt.
    7. Rinse, repeat.

    This is the proper gettext workflow in a nutshell, and it accounts for most problems in the translation process. Especially if you have distributed translators you typically have a time lag and overlap between source code being updated and translations coming in. Without automated string extraction and the msgmerge utility it's easy for this process to devolve into chaos, which is why you should stick to the above steps.

    If you do, your question becomes irrelevant since you can check your PO files at any time using the gettext utilities or a tool like Poedit to see which strings are untranslated.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doulai8128 2012-09-22 15:20

    Probably more important as your in beta would be to do some pseudo localisation, using a tool like podebug. Thus once you've extracted your PO strings you can localise them so that you can see if all strings are extracted in your UI.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题