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

i18n: Remove redundant hasTranslation checks (across the codebase) #98096

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions client/components/domains/use-my-domain/domain-input.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Card, Button, FormInputValidation, Gridicon } from '@automattic/components';
import { englishLocales, useLocale } from '@automattic/i18n-utils';
import { __, hasTranslation } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import PropTypes from 'prop-types';
import { useEffect, useRef } from 'react';
Expand All @@ -25,7 +24,6 @@ function UseMyDomainInput( {
validationError,
} ) {
const domainNameInput = useRef( null );
const locale = useLocale();

useEffect( () => {
shouldSetFocus && domainNameInput.current.focus();
Expand All @@ -47,12 +45,6 @@ function UseMyDomainInput( {
}
};

const hasDomainPlaceholderLabel =
englishLocales.includes( locale ) || hasTranslation( 'yourgroovydomain.com' );
const domainPlaceholderLabel = hasDomainPlaceholderLabel
? __( 'yourgroovydomain.com' )
: __( 'mydomain.com' );

return (
<Card className={ baseClassName }>
{ ! isSignupStep && (
Expand All @@ -64,7 +56,7 @@ function UseMyDomainInput( {
<label>{ __( 'Enter the domain you would like to use:' ) }</label>
<FormFieldset className={ baseClassName + '__domain-input-fieldset' }>
<FormTextInput
placeholder={ domainPlaceholderLabel }
placeholder={ __( 'yourgroovydomain.com' ) }
value={ domainName }
onChange={ onChange }
onKeyDown={ keyDown }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TERM_MONTHLY } from '@automattic/calypso-products';
import i18n, { TranslateResult, getLocaleSlug, useTranslate } from 'i18n-calypso';
import { TranslateResult, useTranslate } from 'i18n-calypso';
import { useMemo } from 'react';
import { useLocalizedMoment } from 'calypso/components/localized-moment';
import type { Duration } from 'calypso/my-sites/plans/jetpack-plans/types';
Expand Down Expand Up @@ -119,42 +119,18 @@ const PartialDiscountTimeFrame: React.FC< PartialDiscountTimeFrameProps & A11yPr

/* eslint-disable wpcalypso/i18n-mismatched-placeholders */
if ( billingTerm === TERM_MONTHLY ) {
if (
getLocaleSlug() === 'en' ||
getLocaleSlug() === 'en-gb' ||
i18n.hasTranslation( 'for the first month, then %(original_price)s /month, billed monthly' )
) {
text = translate(
'for the first month, then %(original_price)s /month, billed monthly',
'for the first %(months)d months, then %(original_price)s /month, billed monthly',
opts
);
} else {
text = translate(
'for the first month, billed monthly',
'for the first %(months)d months, billed monthly',
opts
);
}
text = translate(
'for the first month, then %(original_price)s /month, billed monthly',
'for the first %(months)d months, then %(original_price)s /month, billed monthly',
opts
);
} else {
// eslint-disable-next-line no-lonely-if
if (
getLocaleSlug() === 'en' ||
getLocaleSlug() === 'en-gb' ||
i18n.hasTranslation( 'for the first month, then %(original_price)s /month, billed yearly' )
) {
text = translate(
'for the first month, then %(original_price)s /month, billed yearly',
'for the first %(months)d months, then %(original_price)s /month, billed yearly',
opts
);
} else {
text = translate(
'for the first month, billed yearly',
'for the first %(months)d months, billed yearly',
opts
);
}
text = translate(
'for the first month, then %(original_price)s /month, billed yearly',
'for the first %(months)d months, then %(original_price)s /month, billed yearly',
opts
);
}

if ( forScreenReader ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useIsEnglishLocale } from '@automattic/i18n-utils';
import { IntentScreen, GOOGLE_TRANSFER } from '@automattic/onboarding';
import { Button } from '@wordpress/components';
import { Icon, unlock, plus, payment } from '@wordpress/icons';
Expand All @@ -12,8 +11,7 @@ interface Props {
}

const Intro: React.FC< Props > = ( { onSubmit, variantSlug } ) => {
const { __, hasTranslation } = useI18n();
const isEnglishLocale = useIsEnglishLocale();
const { __ } = useI18n();
const isGoogleDomainsTransferFlow = GOOGLE_TRANSFER === variantSlug;

return (
Expand Down Expand Up @@ -63,16 +61,9 @@ const Intro: React.FC< Props > = ( { onSubmit, variantSlug } ) => {
: __( 'We pay the first year for Google domains' ),
description: (
<p>
{ isEnglishLocale ||
hasTranslation(
{ __(
"Review your payment and contact details. If you're transferring a domain from Squarespace, we'll pay for an additional year of registration if your domain was registered before July 1, 2023."
)
? __(
"Review your payment and contact details. If you're transferring a domain from Squarespace, we'll pay for an additional year of registration if your domain was registered before July 1, 2023."
)
: __(
"Review your payment and contact details. If you're transferring a domain from Google, we'll pay for an additional year of registration."
) }
) }
</p>
),
icon: <Icon icon={ payment } />,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { englishLocales } from '@automattic/i18n-utils';
import { StepContainer } from '@automattic/onboarding';
import styled from '@emotion/styled';
import { useI18n } from '@wordpress/react-i18n';
import { useTranslate } from 'i18n-calypso';
import FormattedHeader from 'calypso/components/formatted-header';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { useSiteDomains } from '../../../../hooks/use-site-domains';
Expand All @@ -17,8 +15,7 @@ const WarningsOrHoldsSection = styled.div`

const ErrorStep: Step = function ErrorStep( { navigation } ) {
const { goBack, goNext } = navigation;
const translate = useTranslate();
const { __, hasTranslation } = useI18n();
const { __ } = useI18n();
const siteDomains = useSiteDomains();
const siteSetupError = useSiteSetupError();

Expand All @@ -29,21 +26,8 @@ const ErrorStep: Step = function ErrorStep( { navigation } ) {
}

const messageCopy = () => {
// New copy waiting on translation.
if (
englishLocales.includes( translate?.localeSlug || '' ) ||
hasTranslation(
'It looks like something went wrong while setting up your site. Please contact support so that we can help you out.'
)
) {
return __(
'It looks like something went wrong while setting up your site. Please contact support so that we can help you out.'
);
}

// Original copy
return __(
'It looks like something went wrong while setting up your store. Please contact support so that we can help you out.'
'It looks like something went wrong while setting up your site. Please contact support so that we can help you out.'
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { isEnabled } from '@automattic/calypso-config';
import { FormLabel } from '@automattic/components';
import { useLocale } from '@automattic/i18n-utils';
import { hasTranslation } from '@wordpress/i18n';
import { useTranslate } from 'i18n-calypso';
import { FC } from 'react';
import { Controller } from 'react-hook-form';
Expand All @@ -10,16 +8,10 @@ import { CredentialsFormFieldProps } from '../types';

export const AccessMethodPicker: FC< CredentialsFormFieldProps > = ( { control } ) => {
const translate = useTranslate();
const locale = useLocale();

const applicationPasswordEnabled = isEnabled( 'automated-migration/application-password' );
const hasLabelTranslation =
locale.startsWith( 'en' ) || hasTranslation( 'WordPress site credentials' );

const credentialsLabel =
applicationPasswordEnabled && hasLabelTranslation
? translate( 'WordPress site credentials' )
: translate( 'WordPress credentials' );
const credentialsLabel = applicationPasswordEnabled
? translate( 'WordPress site credentials' )
: translate( 'WordPress credentials' );

return (
<div>
Expand Down
56 changes: 16 additions & 40 deletions client/lib/domains/resolve-domain-status.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Button } from '@automattic/components';
import { localizeUrl, englishLocales } from '@automattic/i18n-utils';
import { localizeUrl } from '@automattic/i18n-utils';
import {
SETTING_PRIMARY_DOMAIN,
INCOMING_DOMAIN_TRANSFER_STATUSES_IN_PROGRESS,
GDPR_POLICIES,
DOMAIN_EXPIRATION_AUCTION,
} from '@automattic/urls';
import i18n, { getLocaleSlug } from 'i18n-calypso';
import moment from 'moment';
import { useMyDomainInputMode } from 'calypso/components/domains/connect-domain-step/constants';
import { isExpiringSoon } from 'calypso/lib/domains/utils/is-expiring-soon';
Expand Down Expand Up @@ -508,49 +507,26 @@ export function resolveDomainStatus(
domain.transferStatus === transferStatus.COMPLETED &&
! domain.pointsToWpcom
) {
const hasTranslation =
englishLocales.includes( String( getLocaleSlug() ) ) ||
i18n.hasTranslation(
'{{strong}}Transfer successful!{{/strong}} To make this domain work with your WordPress.com site you need to {{a}}point it to WordPress.com.{{/a}}'
);

const oldCopy = translate(
'{{strong}}Transfer successful!{{/strong}} To make this domain work with your WordPress.com site you need to {{a}}point it to WordPress.com name servers.{{/a}}',
{
components: {
strong: <strong />,
a: (
<a
href={ domainManagementEdit( siteSlug as string, domain.domain, currentRoute, {
nameservers: true,
} ) }
/>
),
},
}
);

const newCopy = translate(
'{{strong}}Transfer successful!{{/strong}} To make this domain work with your WordPress.com site you need to {{a}}point it to WordPress.com.{{/a}}',
{
components: {
strong: <strong />,
a: (
<a
href={ domainManagementEdit( siteSlug as string, domain.domain, currentRoute, {
nameservers: true,
} ) }
/>
),
},
}
);
return {
statusText: translate( 'Action required' ),
statusClass: 'status-success',
status: translate( 'Active' ),
icon: 'info',
noticeText: hasTranslation ? newCopy : oldCopy,
noticeText: translate(
'{{strong}}Transfer successful!{{/strong}} To make this domain work with your WordPress.com site you need to {{a}}point it to WordPress.com.{{/a}}',
{
components: {
strong: <strong />,
a: (
<a
href={ domainManagementEdit( siteSlug as string, domain.domain, currentRoute, {
nameservers: true,
} ) }
/>
),
},
}
),
listStatusWeight: 600,
isDismissable: true,
};
Expand Down
40 changes: 7 additions & 33 deletions client/login/magic-login/request-login-email-form.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { FormLabel } from '@automattic/components';
import { englishLocales } from '@automattic/i18n-utils';
import { hasTranslation } from '@wordpress/i18n';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { createRef, Component } from 'react';
Expand Down Expand Up @@ -132,21 +130,14 @@ class RequestLoginEmailForm extends Component {
}

getSubHeaderText() {
const { translate, locale, subHeaderText } = this.props;
const { translate, subHeaderText } = this.props;
const siteName = this.state.site?.name;

if ( subHeaderText ) {
return subHeaderText;
}

// If we have a siteName and new translation is available
if (
siteName &&
( englishLocales.includes( locale ) ||
hasTranslation(
'We’ll send you an email with a login link that will log you in right away to {site name}.'
) )
) {
if ( siteName ) {
return translate(
'We’ll send you an email with a login link that will log you in right away to %(siteName)s.',
{
Expand All @@ -157,19 +148,8 @@ class RequestLoginEmailForm extends Component {
);
}

// If no siteName but new translation is available
if (
englishLocales.includes( locale ) ||
hasTranslation( 'We’ll send you an email with a login link that will log you in right away.' )
) {
return translate(
'We’ll send you an email with a login link that will log you in right away.'
);
}

// Fallback is old text
return translate(
'Get a link sent to the email address associated with your account to log in instantly without your password.'
'We’ll send you an email with a login link that will log you in right away.'
);
}

Expand All @@ -187,7 +167,6 @@ class RequestLoginEmailForm extends Component {
hideSubHeaderText,
inputPlaceholder,
submitButtonLabel,
locale,
customFormLabel,
onSubmitEmail,
errorMessage,
Expand Down Expand Up @@ -223,16 +202,11 @@ class RequestLoginEmailForm extends Component {
? requestError
: translate( 'Unable to complete request' );

const buttonLabel =
englishLocales.includes( locale ) || hasTranslation( 'Send Link' )
? translate( 'Send link' )
: translate( 'Get Link' );
const buttonLabel = translate( 'Send link' );

const formLabel =
customFormLabel ||
( hasTranslation( 'Email address or username' )
? this.props.translate( 'Email address or username' )
: this.props.translate( 'Email Address or Username' ) );
const formLabel = customFormLabel
? this.props.translate( 'Email address or username' )
: this.props.translate( 'Email Address or Username' );

const onSubmit = onSubmitEmail
? ( e ) => onSubmitEmail( this.getUsernameOrEmailFromState(), e )
Expand Down
14 changes: 3 additions & 11 deletions client/me/account/toggle-sites-as-landing-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useHasEnTranslation } from '@automattic/i18n-utils';
import { ToggleControl } from '@wordpress/components';
import { useTranslate } from 'i18n-calypso';
import { useDispatch, useSelector } from 'calypso/state';
Expand Down Expand Up @@ -33,22 +32,15 @@ function ToggleSitesAsLandingPage() {
);
}

const oldCopy = translate( 'Show me all my sites when logging in to WordPress.com' );
const updatedCopy = translate(
'Display all my sites instead of just my primary site when I visit WordPress.com.'
);

const hasTranslationForNewCopy = useHasEnTranslation()(
'Display all my sites instead of just my primary site when I visit WordPress.com.'
);

return (
<div>
<ToggleControl
checked={ !! useSitesAsLandingPage }
onChange={ handleToggle }
disabled={ isSaving }
label={ hasTranslationForNewCopy ? updatedCopy : oldCopy }
label={ translate(
'Display all my sites instead of just my primary site when I visit WordPress.com.'
) }
/>
</div>
);
Expand Down
Loading
Loading