#55081 closed defect (bug) (invalid)
WordPress wp_get_document_title() does not do RTL.
Reported by: | jsmoriss | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | I18N | Keywords: | |
Focuses: | rtl | Cc: |
Description
The WordPress wp_get_document_title() function outputs onlt LTR title strings. ie:
Post Name - Page - Site Name
The output from the 'document_title_parts' filter needs to be ordered (LTR) and then reversed for RTL. ie:
Site Name - Page - Post Name
js.
Attachments (1)
Change History (10)
This ticket was mentioned in Slack in #polyglots by jsmoriss. View the logs.
3 years ago
#2
follow-up:
↓ 3
@
3 years ago
- Focuses rtl added
Hi there, thanks for the patch!
As far as I know, for RTL locales there is no need to reverse the order in cases like this, text direction takes care of that.
That said, it would be great if General Translation Editors for any RTL locales could chime in here and tell whether this is indeed necessary for them or not.
#3
in reply to:
↑ 2
@
3 years ago
Replying to SergeyBiryukov:
As far as I know, for RTL locales there is no need to reverse the order in cases like this, text direction takes care of that.
The text translation, and it's direction, will be correct for each element. This is an array of text strings that is simply imploded. ie.:
Before:
/** * Filters the parts of the document title. * * @since 4.4.0 * * @param array $title { * The document title parts. * * @type string $title Title of the viewed page. * @type string $page Optional. Page number if paginated. * @type string $tagline Optional. Site description when on home page. * @type string $site Optional. Site title when not on home page. * } */ $title = apply_filters( 'document_title_parts', $title ); $title = implode( " $sep ", array_filter( $title ) ); /** * Filters the document title. * * @since 5.8.0 * * @param string $title Document title. */ $title = apply_filters( 'document_title', $title );
And after this patch:
/** * Filters the parts of the document title. * * @since 4.4.0 * * @param array $title { * The document title parts. * * @type string $title Title of the viewed page. * @type string $page Optional. Page number if paginated. * @type string $tagline Optional. Site description when on home page. * @type string $site Optional. Site title when not on home page. * } */ $title = apply_filters( 'document_title_parts', $title ); // Make sure the parts are ordered in a predictable left-to-right sequence. $title = array_merge( array( 'title' => null, 'page' => null, 'site' => null, 'tagline' => null ), $title ); // If this is a right-to-left language, reverse the order of the parts. if ( is_rtl() ) { $title = array_reverse( $title ); } $title = implode( " $sep ", array_filter( $title ) ); /** * Filters the document title. * * @since 5.8.0 * * @param string $title Document title. */ $title = apply_filters( 'document_title', $title );
#4
@
3 years ago
There seems to be some confusion as to the difference between:
1 - An associative array in PHP and how associative arrays are imploded - which behaves the same regardless of the RTL/LTR language. PHP does not magically reorder every single associative array just because the language is RTL - imagine the chaos of that, lol. :)
2 - The translated text of each element within an associative array.
I am trying out outline that (2) may be fine - each element in the array may be translated to an RTL language - but that (1) is not affected by the language - the order of the associative array remains the same.
So, in an RTL language, as the current WordPress wp_get_document_title() function operates, the post name will be left and the site name on the right, regardless of LTR/RTL. I opened this ticket to highlight the fact that the array needs to be reordered for RLT before imploding the elements.
js.
#5
follow-up:
↓ 6
@
3 years ago
So, in an RTL language, as the current WordPress wp_get_document_title() function operates, the post name will be left and the site name on the right, regardless of LTR/RTL.
What Sergey mentioned above is that once the document title is displayed in the browser, the text will be displayed correctly because the browser will change text direction accordingly for RTL languages. Because of that there would be no need to do any array reverse or similar in PHP.
#6
in reply to:
↑ 5
@
3 years ago
Replying to swissspidy:
So, in an RTL language, as the current WordPress wp_get_document_title() function operates, the post name will be left and the site name on the right, regardless of LTR/RTL.
What Sergey mentioned above is that once the document title is displayed in the browser, the text will be displayed correctly because the browser will change text direction accordingly for RTL languages. Because of that there would be no need to do any array reverse or similar in PHP.
So you're saying at all text is left-to-right, even if it's not, and that it's only when being displayed that the browser inverts all text in all strings for a right-to-left language, is that correct? ie. So for PHP, all text strings are left-to-right, regardless of the character code being used - the individual characters may get translated, but not the order of the characters, correct?
js.
Patch for wp-includes/general-template.php