Ticket #9112 (closed enhancement: fixed)
Use gettext's contexts and extracted comments instead of our pipe syntax
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | I18N | Version: | 2.7 |
| Severity: | minor | Keywords: | has-patch |
| Cc: |
Description
Our current (#3687) functionality for disambiguating and adding descriptions to translated strings has some flaws:
- We are using the same syntax (the pipe) for both disambiguating and adding descriptions
- It screws translation memories, because Approved|main page and Approved|adjective are different strings for them
- Translations get confused and often don't get that the text after | is a description or context
Instead, the recent gettext versions provide the following functionality:
- Contexts, which are part of the PO syntax:
msgctxt "context" msgid "term" msgstr "translation"
xgettext supports it and most translation tools too. poEdit works correctly with them, but still doesn't show the context anywhere.
- Extracted comments. If there is a comment directly preceding the gettext call, starting with, let's say translators, it is inserted as a comment in the PO file.
/* translators, see http://php.net/date */ $date = date(__('d.m.Y'));
becomes:
#. translators, see http://php.net/date msgid "d.m.Y" msgstr ""
These comments are shown by all translation software.
Attachments
Change History
comment:1
nbachiyski — 3 years ago
comment:3
nbachiyski — 3 years ago
The current php-gettext library doesn't support contexts. I've got a rewritten, slightly more abstracted, cleaner and having some tests gettext library at http://svn.glotpress.org/trunk/pomo/
I will send a patch soon.
comment:4
nbachiyski — 3 years ago
- Keywords has-patch added
Here is a patch, which switches from current php-gettext to the GlotPress one. It expects the new library files to be in wp-includes/pomo. In the beginning we can add it as an external and then we can trim it just to the needed files.
wp-includes/gettext.php and wp-includes/streams.php aren't needed any more.
I named the new context functions _x and _nx. It resembles conteXt.
Note: the patch includes the deprecation part from #9111.
- Status changed from new to closed
- Resolution set to fixed
Went ahead and added pomo as a real directory instead of an external since switching from an external to a directory always seems to cause grief. We'll just have to keep it in sync.
nbachiyski — 3 years ago
-
attachment
i18n-gettext-contexts-0.diff
added
First patch using _x and extracted coments
comment:7
nbachiyski — 3 years ago
- Status changed from closed to reopened
- Resolution fixed deleted
Here is the first patch, which adds some _x() calls and uses extracted comments like translators: instead of _c().
comment:9
nbachiyski — 3 years ago
Next round of _x and comments. Role names caused some trouble, because they are kept in DB and currently their values have the |Role name suffix.
comment:10
ryan — 3 years ago
comment:11
nbachiyski — 3 years ago
The last patch of the series, a little bit larger than the previous ones.
Fixes several other minor problems:
- adds a lot of translator comments
- noop functions don't need to have similar interface to the standard gettext functions, so I got rid of the dummy args
- feed_links had separator spelled as seperator and a typo in one of the indices
- _x didn't have a dummy entry in the script/style loadign scrits
comment:12
ryan — 3 years ago
comment:13
nbachiyski — 3 years ago
Another patch, which consolidates time format in timezone options.

There is already support for this in the POT generating tools in http://svn.automattic.com/wordpress-i18n/tools/trunk/