Skip to content

Commit

Permalink
i18n: Make the date format in RelativeTime component translatable (#8…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliyan authored and pull[bot] committed Nov 10, 2023
1 parent 7624ef9 commit 4097219
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions client/my-sites/promote-post-i2/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '@automattic/calypso-config';
import { InfiniteData } from '@tanstack/react-query';
import { __ } from '@wordpress/i18n';
import { __, _x } from '@wordpress/i18n';
import moment from 'moment';
import {
BlazablePost,
Expand Down Expand Up @@ -115,8 +115,10 @@ export const getCampaignDurationFormatted = ( start_date?: string, end_date?: st
if ( campaignDays === 0 ) {
durationFormatted = '-';
} else {
const dateStartFormatted = moment.utc( start_date ).format( 'MMM D' );
const dateEndFormatted = moment.utc( end_date ).format( 'MMM D' );
// translators: Moment.js date format, `MMM` refers to short month name (e.g. `Sep`), `D`` refers to day of month (e.g. `5`). Wrap text [] to be displayed as is, for example `D [de] MMM` will be formatted as `5 de sep.`.
const format = _x( 'MMM D', 'shorter date format' );
const dateStartFormatted = moment.utc( start_date ).format( format );
const dateEndFormatted = moment.utc( end_date ).format( format );
durationFormatted = `${ dateStartFormatted } - ${ dateEndFormatted }`;
}

Expand Down Expand Up @@ -243,9 +245,13 @@ export const getShortDateString = ( date: string ) => {
return timestamp.fromNow();
}

return timestamp.isSame( now, 'year' )
? moment( date ).format( 'MMM DD' )
: moment( date ).format( 'MMM DD, YYYY' );
const format = timestamp.isSame( now, 'year' )
? // translators: Moment.js date format, `MMM` refers to short month name (e.g. `Sep`), `DD`` refers to 2-digit day of month (e.g. `05`). Wrap text [] to be displayed as is, for example `DD [de] MMM` will be formatted as `05 de sep.`.
_x( 'MMM DD', 'short date format' )
: // translators: Moment.js date format, `MMM` refers to short month name (e.g. `Sep`), `DD`` refers to 2-digit day of month (e.g. `05`), `YYYY` refers to the full year format (e.g. `2023`). Wrap text [] to be displayed as is, for example `DD [de] MMM [de] YYYY` will be formatted as `05 de sep. de 2023`.
_x( 'MMM DD, YYYY', 'short date with year format' );

return moment( date ).format( format );
};

export const getLongDateString = ( date: string ) => {
Expand Down

0 comments on commit 4097219

Please sign in to comment.