Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 11 years ago

#9112 closed enhancement (fixed)

Use gettext's contexts and extracted comments instead of our pipe syntax

Reported by: nbachiyski's profile nbachiyski Owned by: nbachiyski's profile nbachiyski
Milestone: 2.8 Priority: normal
Severity: minor Version: 2.7
Component: I18N Keywords: has-patch
Focuses: Cc:


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 */
    $date = date(__('d.m.Y'));


#. translators, see
msgid "d.m.Y"
msgstr ""

These comments are shown by all translation software.

Attachments (5)

new-gettext-lib.diff (8.9 KB) - added by nbachiyski 15 years ago.
i18n-gettext-contexts-0.diff (18.9 KB) - added by nbachiyski 15 years ago.
First patch using _x and extracted coments
i18n-gettext-contexts-1.diff (12.9 KB) - added by nbachiyski 15 years ago.
i18n-gettext-contexts-2.diff (35.8 KB) - added by nbachiyski 15 years ago.
i18n-gettext-contexts-3.diff (2.9 KB) - added by nbachiyski 15 years ago.
Timezones format

Download all attachments as: .zip

Change History (22)

#1 @nbachiyski
15 years ago

There is already support for this in the POT generating tools in

#2 @ryan
15 years ago

And functions to handle pgettext() and npgettext()?

#3 @nbachiyski
15 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

I will send a patch soon.

#4 @nbachiyski
15 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.

#5 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10584]) Switch to pomo lib. Support gettext contexts. Deprecate long form functions. Props nbachiyski. fixes #9112 #9111

#6 @ryan
15 years ago

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.

15 years ago

First patch using _x and extracted coments

#7 @nbachiyski
15 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Here is the first patch, which adds some _x() calls and uses extracted comments like translators: instead of _c().

#8 @ryan
15 years ago

(In [10680]) Use _x() and extracted comments. Props nbachiyski. see #9112

#9 @nbachiyski
15 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.

#10 @ryan
15 years ago

(In [10767]) gettext contexts. Props nbachiyski. see #9112

#11 @nbachiyski
15 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

#12 @ryan
15 years ago

(In [10774]) gettext comments. Props nbachiyski. see #9112

15 years ago

Timezones format

#13 @nbachiyski
15 years ago

Another patch, which consolidates time format in timezone options.

#14 @westi
15 years ago

(In [10836]) Improve translation support for timezone settings. See #9112 props nbachiyski.

#15 @nbachiyski
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

#16 @nbachiyski
15 years ago

  • Milestone 2.8 deleted

#17 @DrewAPicture
11 years ago

  • Milestone set to 2.8
Note: See TracTickets for help on using tickets.