WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 10 months ago

#9112 closed enhancement (fixed)

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

Reported by: nbachiyski Owned by: nbachiyski
Milestone: 2.8 Priority: normal
Severity: minor Version: 2.7
Component: I18N Keywords: has-patch
Focuses: 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 (5)

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

Download all attachments as: .zip

Change History (22)

comment:1 nbachiyski5 years ago

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

comment:2 ryan5 years ago

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

comment:3 nbachiyski5 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 nbachiyski5 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.

nbachiyski5 years ago

comment:5 ryan5 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

comment:6 ryan5 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.

nbachiyski5 years ago

First patch using _x and extracted coments

comment:7 nbachiyski5 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().

comment:8 ryan5 years ago

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

comment:9 nbachiyski5 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 ryan5 years ago

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

comment:11 nbachiyski5 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 ryan5 years ago

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

nbachiyski5 years ago

Timezones format

comment:13 nbachiyski5 years ago

Another patch, which consolidates time format in timezone options.

comment:14 westi5 years ago

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

comment:15 nbachiyski5 years ago

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

comment:16 nbachiyski5 years ago

  • Milestone 2.8 deleted

comment:17 DrewAPicture10 months ago

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