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

Use wordpress i 18 n in all of our codebase [MAILPOET-4908] #4627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3c618ed
Add newsletter_editor.js using AssetsController
samnajian Dec 29, 2022
db9107b
Fix memory issue when building translations
samnajian Dec 29, 2022
cfc8ba6
Remove editor translations from tpl and add via wp/i18n
samnajian Dec 29, 2022
3ed3d8b
Use translator from @wordpress/i18n in newsletter app
samnajian Jan 1, 2023
7b62b14
Use wp/i18n in components that's used for newsletter app
samnajian Jan 2, 2023
a03157a
Unify wording that was causing tests to fail
samnajian Jan 3, 2023
9939e71
Move code around to make registerTranslations accesable
samnajian Jan 4, 2023
be7db66
Make sure translations are loaded for newsletter editor
samnajian Jan 4, 2023
23d28e4
Fix issue causing newsletter tests to fail
samnajian Jan 4, 2023
6c7ce79
Translate some more common strings using wp/i18n
samnajian Jan 4, 2023
dd591bd
Enqueue newletter assest using asset controller
samnajian Jan 4, 2023
0909211
Add admin.js to all admin pages using AssetController
samnajian Jan 6, 2023
6a72297
Fix regression for newly added translation
samnajian Feb 16, 2023
2a78525
Add missing translation
samnajian Mar 7, 2023
ea9e144
Use @wordpress/i18n for coupon block
samnajian Mar 7, 2023
80949f3
Fix wrong import order
samnajian Mar 7, 2023
c7041c6
Add missing translatable messages
samnajian Mar 7, 2023
347d17b
Fix code formatting issue
samnajian Mar 7, 2023
a453f5b
Fix the issue in image block not working with lodash
samnajian Mar 7, 2023
5126750
Manually bump version to beta.1
samnajian Mar 8, 2023
79ecd1a
Wait for coupon settings panel to close before proceeding
samnajian Mar 8, 2023
8ba94cd
Use @wordpress/i18n for template boxes
samnajian Mar 8, 2023
c575906
Use @wordpress/i18n for rest of common folder
samnajian Mar 8, 2023
e2bd7ca
Add commons.js via wp_enqueue_script
samnajian Mar 8, 2023
6a81218
Manually bump version to beta.3
samnajian Mar 8, 2023
d26ec6f
Fix issue with newsletter form fields not getting translated
samnajian Mar 9, 2023
00f1b5d
Add missing code back
samnajian Mar 9, 2023
f392aeb
Adjust translations:build command to use wp from vendor dir
samnajian Mar 10, 2023
3b2b4c3
Exclude irrelevant files from being parsed for translations
samnajian Mar 10, 2023
84fc7bf
Add a missing translations
samnajian Mar 10, 2023
e2f0ac4
Fix translation for frequency in for re-engagement emails
samnajian Mar 13, 2023
13a8587
Add missing translation domains
samnajian Mar 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion mailpoet/RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public function translationsBuild() {
'tools',
'vendor',
'vendor-prefixed',
'RoboFile.php',
'.storybook',
'storybook-static',
]);

$headers = escapeshellarg(
Expand All @@ -153,7 +156,7 @@ public function translationsBuild() {
->taskExec("php -d memory_limit=-1 tasks/makepot/makepot-views.php . > lang/mailpoet.pot")

// PHP, JS/TS
->taskExec("vendor/bin/wp i18n make-pot --merge --slug=mailpoet --domain=mailpoet --exclude=$exclude --headers=$headers . lang/mailpoet.pot")
->taskExec("php -d memory_limit=-1 vendor/wp-cli/wp-cli/php/boot-fs.php i18n make-pot --merge --slug=mailpoet --domain=mailpoet --exclude=$exclude --headers=$headers . lang/mailpoet.pot")

->run();
}
Expand Down
2 changes: 1 addition & 1 deletion mailpoet/assets/js/src/automation/automation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BrowserRouter } from 'react-router-dom';
import { TopBarWithBeamer } from 'common/top_bar/top_bar';
import { Popover, SlotFillProvider } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { registerTranslations } from 'common';
import { initializeApi } from './api';
import { registerTranslations } from './i18n';
import { createStore, storeName } from './listing/store';
import { AutomationListing, AutomationListingHeader } from './listing';
import { registerApiErrorHandler } from './listing/api-error-handler';
Expand Down
2 changes: 1 addition & 1 deletion mailpoet/assets/js/src/automation/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { registerTranslations } from 'common';
import { Header } from './components/header';
import { InserterSidebar } from './components/inserter-sidebar';
import { KeyboardShortcuts } from './components/keyboard-shortcuts';
Expand All @@ -27,7 +28,6 @@ import { MailPoet } from '../../mailpoet';
import { LISTING_NOTICE_PARAMETERS } from '../listing/automation-listing-notices';
import { registerApiErrorHandler } from './api-error-handler';
import { ActivatePanel } from './components/panel/activate-panel';
import { registerTranslations } from '../i18n';
import { AutomationStatus } from '../listing/automation';

// See:
Expand Down
2 changes: 1 addition & 1 deletion mailpoet/assets/js/src/automation/templates/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ReactDOM from 'react-dom';
import { __ } from '@wordpress/i18n';
import { Flex } from '@wordpress/components';
import { registerTranslations } from 'common';
import { automationTemplates } from './config';
import { TemplateListItem } from './components/template-list-item';
import { initializeApi } from '../api';
import { registerTranslations } from '../i18n';
import { TopBarWithBeamer } from '../../common/top_bar/top_bar';
import {
FromScratchButton,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { __ } from '@wordpress/i18n';
import { MailPoet } from 'mailpoet';
import classnames from 'classnames';
import { extractEmailDomain, extractPageNameFromUrl } from 'common/functions';
Expand Down Expand Up @@ -100,9 +101,7 @@ function AuthorizeSenderEmailAndDomainModal({
className={classnames({
mailpoet_hidden: !showSenderEmailTab,
})}
title={MailPoet.I18n.t(
'authorizeSenderEmailAndDomainModalSenderEmailTabTitle',
)}
title={__('Authorized emails', 'mailpoet')}
>
{showSenderEmailTab && (
<AuthorizeSenderEmailModal
Expand All @@ -123,9 +122,7 @@ function AuthorizeSenderEmailAndDomainModal({
className={classnames({
mailpoet_hidden: !showSenderDomainTab,
})}
title={MailPoet.I18n.t(
'authorizeSenderEmailAndDomainModalSenderDomainTabTitle',
)}
title={__('Sender Domains', 'mailpoet')}
>
{showSenderDomainTab && (
<AuthorizeSenderDomainModal
Expand Down
32 changes: 23 additions & 9 deletions mailpoet/assets/js/src/common/authorize_sender_email_modal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useEffect, useRef, useState } from 'react';
import ReactStringReplace from 'react-string-replace';
import moment from 'moment';
import { __ } from '@wordpress/i18n';
import { MailPoet } from 'mailpoet';
import { Modal } from 'common/modal/modal';
import { Button, Loader } from 'common';
import { isErrorResponse, ErrorResponse } from 'ajax';
import { ErrorResponse, isErrorResponse } from 'ajax';
import { Grid } from 'common/grid';

const SET_INTERVAL_PERFORM_REQUEST_EVERY_SECONDS = 15;
Expand Down Expand Up @@ -187,7 +188,10 @@ function AuthorizeSenderEmailModal({
{createEmailApiResponse && (
<p>
{ReactStringReplace(
MailPoet.I18n.t('authorizeSenderEmailModalDescription'),
__(
'Check your inbox now to confirm your email address. Please find the email with the subject: [bold]"email address to authorize"[/bold]',
'mailpoet',
),
/\[bold\](.*?)\[\/bold\]/g,
(match, i) => (
<strong key={i}>{match}</strong>
Expand All @@ -198,7 +202,12 @@ function AuthorizeSenderEmailModal({
{createEmailApiResponse === false && (
<>
<strong> {createEmailApiError} </strong>
<p>{MailPoet.I18n.t('authorizeSenderEmailMessageError')}</p>
<p>
{__(
'An error occured when performing the request. Please try again later',
'mailpoet',
)}
</p>
</>
)}

Expand All @@ -210,10 +219,15 @@ function AuthorizeSenderEmailModal({

{confirmEmailApiResponse && (
<>
<p>{MailPoet.I18n.t('authorizeSenderEmailMessageSuccess')}</p>
<p>
{__(
'The email address has been authorized. You can now send emails using this address with MailPoet.',
'mailpoet',
)}
</p>
<Button onClick={onRequestClose} className="button-on-top">
{' '}
{MailPoet.I18n.t('close')}{' '}
{__('Close', 'mailpoet')}{' '}
</Button>
</>
)}
Expand All @@ -222,10 +236,10 @@ function AuthorizeSenderEmailModal({

return useModal ? (
<Modal
title={MailPoet.I18n.t('authorizeSenderEmailModalTitle').replace(
'[senderEmail]',
senderEmailAddress,
)}
title={__(
'Authorizing your email address: [senderEmail]',
'mailpoet',
).replace('[senderEmail]', senderEmailAddress)}
onRequestClose={onRequestClose}
contentClassName="authorize-sender-email-modal"
>
Expand Down
10 changes: 6 additions & 4 deletions mailpoet/assets/js/src/common/confirm_alert.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { MailPoet } from 'mailpoet';
import { __ } from '@wordpress/i18n';
import PropTypes from 'prop-types';
import ReactDOMServer from 'react-dom/server';

import { MailPoet } from 'mailpoet';

function ConfirmAlert(props) {
MailPoet.Modal.popup({
title: props.title,
Expand Down Expand Up @@ -49,9 +51,9 @@ ConfirmAlert.propTypes = {
};

ConfirmAlert.defaultProps = {
title: MailPoet.I18n.t('confirmTitle'),
cancelLabel: MailPoet.I18n.t('cancelLabel'),
confirmLabel: MailPoet.I18n.t('confirmLabel'),
title: __('Confirm to proceed', 'mailpoet'),
cancelLabel: __('Cancel', 'mailpoet'),
confirmLabel: __('Confirm', 'mailpoet'),
};

export function confirmAlert(props) {
Expand Down
1 change: 1 addition & 0 deletions mailpoet/assets/js/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './form';
export * from './tag';
export * from './listings';
export * from './error_boundary';
export * from './translations';
export * from './functions';
export * from './utils';
export * from './thumbnail';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import { MailPoet } from 'mailpoet';
import { NewsletterStats } from '../newsletter_stats';
import { Heading } from '../../typography/heading/heading';

MailPoet.I18n.add('excellentBadgeName', 'Excellent');
MailPoet.I18n.add('excellentBadgeTooltip', 'Congrats!');
MailPoet.I18n.add('goodBadgeName', 'Good');
MailPoet.I18n.add('goodBadgeTooltip', 'Good stuff.');
MailPoet.I18n.add('criticalBadgeName', 'Critical');
MailPoet.I18n.add('criticalBadgeTooltip', 'Something to improve.');
MailPoet.I18n.add('openedStatTooltipExcellent', 'above 30%');
MailPoet.I18n.add('openedStatTooltipGood', 'between 10 and 30%');
MailPoet.I18n.add('openedStatTooltipCritical', 'under 10%');
MailPoet.I18n.add('clickedStatTooltipExcellent', 'above 3%');
MailPoet.I18n.add('clickedStatTooltipGood', 'between 1 and 3%');
MailPoet.I18n.add('clickedStatTooltipCritical', 'under 1%');
MailPoet.I18n.add(
'revenueStatsTooltipShort',
'Revenues by customer who clicked on this email in the last 2 weeks.',
);

export default {
title: 'Listing',
component: NewsletterStats,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { addHours, subHours } from 'date-fns';
import { MailPoet } from 'mailpoet';
import { NewsletterStatus as NewsletterStatusEnum } from 'common/newsletter';
import { NewsletterStatus } from '../newsletter_status';
import { Heading } from '../../typography';

MailPoet.I18n.add('notSentYet', 'Not sent yet!');
MailPoet.I18n.add('sent', 'Sent');
MailPoet.I18n.add('paused', 'Paused');

export default {
title: 'Listing',
component: NewsletterStatus,
Expand Down
6 changes: 5 additions & 1 deletion mailpoet/assets/js/src/common/listings/newsletter_stats.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReactNode } from 'react';
import { __ } from '@wordpress/i18n';
import { MailPoet } from 'mailpoet';
import { StatsBadge } from './newsletter_stats/stats';
import { Tooltip } from '../tooltip/tooltip';
Expand Down Expand Up @@ -63,7 +64,10 @@ export function NewsletterStats({
</Tag>
<Tooltip place="top" multiline id={revenuesTooltipId}>
<div className="mailpoet-listing-stats-tooltip-content">
{MailPoet.I18n.t('revenueStatsTooltipShort')}
{__(
'Revenues by customers who clicked on this email in the last 2 weeks.',
'mailpoet',
)}
</div>
</Tooltip>
</div>
Expand Down
38 changes: 19 additions & 19 deletions mailpoet/assets/js/src/common/listings/newsletter_stats/stats.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MailPoet } from 'mailpoet';
import { __, _x } from '@wordpress/i18n';
import { Place } from 'react-tooltip';
import { Badge } from './badge';

Expand All @@ -15,36 +15,36 @@ const stats = {
badgeRanges: [30, 10, 0],
badgeTypes: ['excellent', 'good', 'critical'],
tooltipText: {
excellent: MailPoet.I18n.t('openedStatTooltipExcellent'),
good: MailPoet.I18n.t('openedStatTooltipGood'),
critical: MailPoet.I18n.t('openedStatTooltipCritical'),
excellent: _x('above 30%', 'Excellent open rate', 'mailpoet'),
good: _x('between 10 and 30%', 'Good open rate', 'mailpoet'),
critical: _x('under 10%', 'Critical open rate', 'mailpoet'),
},
},
clicked: {
badgeRanges: [3, 1, 0],
badgeTypes: ['excellent', 'good', 'critical'],
tooltipText: {
excellent: MailPoet.I18n.t('clickedStatTooltipExcellent'),
good: MailPoet.I18n.t('clickedStatTooltipGood'),
critical: MailPoet.I18n.t('clickedStatTooltipCritical'),
excellent: _x('above 3%', 'Excellent click rate', 'mailpoet'),
good: _x('between 1 and 3%', 'Good click rate', 'mailpoet'),
critical: _x('under 1%', 'Critical click rate', 'mailpoet'),
},
},
bounced: {
badgeRanges: [1.5, 0.5, 0],
badgeTypes: ['critical', 'good', 'excellent'],
tooltipText: {
excellent: MailPoet.I18n.t('bouncedStatTooltipExcellent'),
good: MailPoet.I18n.t('bouncedStatTooltipGood'),
critical: MailPoet.I18n.t('bouncedStatTooltipCritical'),
excellent: _x('below 0.5%', 'Excellent bounce rate', 'mailpoet'),
good: _x('between 0.5% and 1.5%', 'Good bounce rate', 'mailpoet'),
critical: _x('above 1.5%', 'Critical bounce rate', 'mailpoet'),
},
},
unsubscribed: {
badgeRanges: [0.7, 0.3, 0],
badgeTypes: ['critical', 'good', 'excellent'],
tooltipText: {
excellent: MailPoet.I18n.t('unsubscribeStatTooltipExcellent'),
good: MailPoet.I18n.t('unsubscribeStatTooltipGood'),
critical: MailPoet.I18n.t('unsubscribeStatTooltipCritical'),
excellent: _x('Below 0.3%', 'Excellent unsubscribe rate', 'mailpoet'),
good: _x('between 0.3% and 0.7%', 'Good unsubscribe rate', 'mailpoet'),
critical: _x('above 0.7%', 'Critical unsubscribe rate', 'mailpoet'),
},
},
};
Expand All @@ -71,16 +71,16 @@ export const getBadgeType = (statName, rate) => {
function StatsBadge(props: StatsBadgeProps) {
const badges = {
excellent: {
name: MailPoet.I18n.t('excellentBadgeName'),
tooltipTitle: MailPoet.I18n.t('excellentBadgeTooltip'),
name: __('Excellent', 'mailpoet'),
tooltipTitle: __('Congrats!', 'mailpoet'),
},
good: {
name: MailPoet.I18n.t('goodBadgeName'),
tooltipTitle: MailPoet.I18n.t('goodBadgeTooltip'),
name: __('Good', 'mailpoet'),
tooltipTitle: __('Good stuff.', 'mailpoet'),
},
critical: {
name: MailPoet.I18n.t('criticalBadgeName'),
tooltipTitle: MailPoet.I18n.t('criticalBadgeTooltip'),
name: __('Critical', 'mailpoet'),
tooltipTitle: __('Something to improve.', 'mailpoet'),
},
};

Expand Down
14 changes: 8 additions & 6 deletions mailpoet/assets/js/src/common/listings/newsletter_status.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { __ } from '@wordpress/i18n';
import { MailPoet } from 'mailpoet';
import classnames from 'classnames';
import { addDays, differenceInMinutes, isFuture, isPast } from 'date-fns';
import { t } from 'common/functions/t';
import {
NewsLetter,
NewsletterStatus as NewsletterStatusEnum,
Expand Down Expand Up @@ -84,7 +84,7 @@ function NewsletterStatus({
const sent = (!scheduledFor || isPast(scheduledFor)) && processed >= total;
const sentWithoutQueue = status === 'sent' && total === undefined;
let percentage = 0;
let label: string | JSX.Element = t('notSentYet');
let label: string | JSX.Element = __('Not sent yet!', 'mailpoet');
if (scheduled) {
const scheduledDate = MailPoet.Date.short(scheduledFor);
const scheduledTime = MailPoet.Date.time(scheduledFor);
Expand All @@ -95,7 +95,9 @@ function NewsletterStatus({
MailPoet.Date.short(tomorrow) === scheduledDate;
if (isScheduledForToday || isScheduledForTomorrow) {
const randomId = Math.random().toString(36).substring(2, 15);
const dateWord = isScheduledForToday ? t('today') : t('tomorrow');
const dateWord = isScheduledForToday
? __('Today', 'mailpoet')
: __('Tomorrow', 'mailpoet');
label = (
<>
<span data-tip data-for={randomId}>
Expand Down Expand Up @@ -135,15 +137,15 @@ function NewsletterStatus({
)} / ${MailPoet.Num.toLocaleFixed(total)}`;
percentage = 100;
} else if (sentWithoutQueue) {
label = t('sent');
label = __('Sent', 'mailpoet');
percentage = 100;
}
if (isPaused && !sent && !sentWithoutQueue) {
label = t('paused');
label = __('Paused', 'mailpoet');
}

if (isCorrupt) {
label = t('renderingProblem');
label = __('There was a problem with rendering!', 'mailpoet');
}

return (
Expand Down