Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internationalization: PostScheduleLabel format cannot easily be translated and makes for incorrect English phrases #67487

Open
3 of 6 tasks
jeherve opened this issue Dec 2, 2024 · 2 comments
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Bug An existing feature does not function as intended

Comments

@jeherve
Copy link
Contributor

jeherve commented Dec 2, 2024

Description

The PostScheduleLabel component does not always display a full date ; in some scenarios it uses words, like "Today", or "Tomorrow":

export function getPostScheduleLabel(
dateAttribute,
{ isFloating = false, now = new Date() } = {}
) {
if ( ! dateAttribute || isFloating ) {
return __( 'Immediately' );
}
// If the user timezone does not equal the site timezone then using words
// like 'tomorrow' is confusing, so show the full date.
if ( ! isTimezoneSameAsSiteTimezone( now ) ) {
return getFullPostScheduleLabel( dateAttribute );
}
const date = getDate( dateAttribute );
if ( isSameDay( date, now ) ) {
return sprintf(
// translators: %s: Time of day the post is scheduled for.
__( 'Today at %s' ),
// translators: If using a space between 'g:i' and 'a', use a non-breaking space.
dateI18n( _x( 'g:i\xa0a', 'post schedule time format' ), date )
);
}
const tomorrow = new Date( now );
tomorrow.setDate( tomorrow.getDate() + 1 );
if ( isSameDay( date, tomorrow ) ) {
return sprintf(
// translators: %s: Time of day the post is scheduled for.
__( 'Tomorrow at %s' ),
// translators: If using a space between 'g:i' and 'a', use a non-breaking space.
dateI18n( _x( 'g:i\xa0a', 'post schedule time format' ), date )
);
}

This is not ideal as the date can be used as part of a sentence in the post-publish panel:

<>
{ __( 'is now scheduled. It will go live on' ) }{ ' ' }
<PostScheduleLabel />.
</>

It becomes hard for translators to translate that phrase (not all languages are built that way) and even make for incorrect phrases in English.

Ideally, I think this should be broken into different strings based on the type of string outputted by PostScheduleLabel.


This was also discussed here:
#56854 (comment)

Step-by-step reproduction instructions

  1. Go to Posts > Add New
  2. Write a new post
  3. Schedule it to be published tomorrow
  4. See the post-publish panel.

Screenshots, screen recording, code snippet

Image

Environment info

Note that your site's timezone in Settings > General must match your own.

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@jeherve jeherve added the [Type] Bug An existing feature does not function as intended label Dec 2, 2024
@CoderAbhinav
Copy link

CoderAbhinav commented Dec 5, 2024

We can break the sentence ‘is now scheduled. It will go live on’ such that, the <PostScheduleLabel/> component will return a full sentence rather than just returning “Today” / “Tomorrow” / Date. So the translators will be able to simply write the translations for the fill string, providing a better context and arrangement.

Since the same component is also used here, we either need to create a separate label for the same purpose.

<PanelBody
initialOpen={ false }
title={ [
__( 'Publish:' ),
<span
className="editor-post-publish-panel__link"
key="label"
>
<PostScheduleLabel />
</span>,

@CoderAbhinav
Copy link

CoderAbhinav commented Dec 5, 2024

I have added my solution in this PR: #67614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants