Skip to content

i18n: The "Written by" byline can't be reordered for other languages #218

Closed

Description

@t-hamano

What happened?

The single post templates build the byline from two blocks: a paragraph with esc_html_e( 'Written by ', 'ipsum' ), followed by a Post Author Name block.

<p class="has-manrope-font-family has-small-font-size" style="font-style:normal;font-weight:600"><?php esc_html_e( 'Written by&nbsp;', 'ipsum' ); ?></p>

<p class="has-manrope-font-family has-small-font-size" style="font-style:normal;font-weight:600"><?php esc_html_e( 'Written by&nbsp;', 'ipsum' ); ?></p>

In general, visible text shouldn't be built by concatenating translatable strings, because the word order is then fixed by the code rather than by the translation. Here, translators can only translate "Written by" and can't move the author name. Languages that put the name first, such as Japanese ({authorName} 著), can't produce a natural byline.

One way to fix this is a block binding, like the existing ipsum/comments-cta source. The paragraph would be bound to a new source that returns the whole byline as one translatable string, with a placeholder for the author name:

function ipsum_byline_binding( $source_args, $block_instance ) {
	unset( $source_args );
	$post = get_post( $block_instance->context['postId'] ?? null );
	if ( ! $post ) {
		return null;
	}
	$author = sprintf(
		'<a href="%1$s">%2$s</a>',
		esc_url( get_author_posts_url( (int) $post->post_author ) ),
		esc_html( get_the_author_meta( 'display_name', $post->post_author ) )
	);
	/* translators: %s: Post author name. */
	return sprintf( __( 'Written by %s', 'ipsum' ), $author );
}

The trade-off is that the author name is no longer a separate block, so it can't be styled on its own. Today the byline and the name share the same font and weight, so the look wouldn't change.

Where does it happen?

On the site (front end)

Steps to reproduce

  1. Open a single post.
  2. See the byline "Written by" followed by the author name.
  3. Look at patterns/hidden-single.php:47. See that only "Written by " is translatable and the author name is a separate block, so the order is fixed.

Screenshots or screen recording

No response

WordPress version

7.2-beta5-65401

PHP version

8.3

Ipsum version

git clone at commit fdfda0a

Gutenberg plugin version

installed

Browser and device

No response

Before you submit

  • I searched the existing issues and this bug hasn't been reported yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions