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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top