Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#51429 closed defect (bug) (worksforme)

Translation not work in get_the_archive_title after changes with translation in context (_x())

Reported by: tomaskavalek's profile tomaskavalek Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.5
Component: Themes Keywords:
Focuses: template Cc:

Description

After adding this:

<?php
        if ( $prefix ) {
                $title = sprintf(
                        /* translators: 1: Title prefix. 2: Title. */
                        _x( '%1$s %2$s', 'archive title' ),
                        $prefix,
                        '<span>' . $title . '</span>'
                );
        }

There is a big problem with translation, because

'%1$s %2$s'

cannot be translated, even with context, by default.

This function return original text in English, eg.: Category: Test, without prefix translation.

Change History (3)

#1 follow-up: @ocean90
3 years ago

  • Component changed from General to Themes
  • Focuses template added
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
  • Version changed from 5.5.1 to 5.5

Hi @tomaskavalek, welcome to WordPress Trac!

Thanks for the report. This was introduced in [48294]. The line is only intended to allow translators changing the order and/or adding something between the prefix and title.
The prefix itself is also available for translation just a few lines above, e.g. $prefix = _x( 'Category:', 'category archive title prefix' );.

#2 in reply to: ↑ 1 ; follow-up: @tomaskavalek
3 years ago

Replying to ocean90:

Hi @tomaskavalek, welcome to WordPress Trac!

Thanks for the report. This was introduced in [48294]. The line is only intended to allow translators changing the order and/or adding something between the prefix and title.
The prefix itself is also available for translation just a few lines above, e.g. $prefix = _x( 'Category:', 'category archive title prefix' );.

Thanks for your fast reply. I tried lot of steps, but it doesn't work as in previous version. I think that problem is in CONTEXT, which is required in _x() and msgctxt is not included in translation files of WordPress core.

Did you test it? Thanks a lot.

#3 in reply to: ↑ 2 @SergeyBiryukov
3 years ago

Replying to tomaskavalek:

Thanks for your fast reply. I tried lot of steps, but it doesn't work as in previous version. I think that problem is in CONTEXT, which is required in _x() and msgctxt is not included in translation files of WordPress core.

If you download the wordpress.pot file, msgctxt is included there:

#. translators: 1: Title prefix. 2: Title.
#: wp-includes/general-template.php:1728
msgctxt "archive title"
msgid "%1$s %2$s"
msgstr ""

There are a lot of other instances of _x() in core. As far as I can see, this one doesn't seem any different from them.

Note: See TracTickets for help on using tickets.