Skip to content

Commit

Permalink
Upgrade react-intl (mastodon#24906)
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap committed May 31, 2023
1 parent 00c2223 commit 44cd88a
Show file tree
Hide file tree
Showing 130 changed files with 413 additions and 5,046 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ module.exports = {
'.*rc.js',
'ide-helper.js',
'config/webpack/**/*',
'config/formatjs-formatter.js',
],

env: {
Expand Down
12 changes: 0 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ updates:
- dependency-name: 'react-hotkeys'
versions:
- '>= 2'
# TODO: This version has breaking changes
- dependency-name: 'intl-messageformat'
versions:
- '>= 3'
# TODO: This version has breaking changes
- dependency-name: 'react-intl'
versions:
- '>= 3'
# TODO: This version has breaking changes
- dependency-name: 'babel-plugin-react-intl'
versions:
- '>= 7'
# TODO: This version requires code changes
- dependency-name: 'webpack-dev-server'
versions:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/check-i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ jobs:

- name: Check for missing strings in English JSON
run: |
yarn build:development
yarn manage:translations en
yarn i18n:extract --throws
git diff --exit-code
- name: Check locale file normalization
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/actions/notifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IntlMessageFormat from 'intl-messageformat';
import { IntlMessageFormat } from 'intl-messageformat';
import { defineMessages } from 'react-intl';

import { List as ImmutableList } from 'immutable';
Expand Down
11 changes: 5 additions & 6 deletions app/javascript/mastodon/components/domain.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback } from 'react';

import type { InjectedIntl } from 'react-intl';
import { defineMessages, injectIntl } from 'react-intl';
import { defineMessages, useIntl } from 'react-intl';

import { IconButton } from './icon_button';

Expand All @@ -15,9 +14,11 @@ const messages = defineMessages({
interface Props {
domain: string;
onUnblockDomain: (domain: string) => void;
intl: InjectedIntl;
}
const _Domain: React.FC<Props> = ({ domain, onUnblockDomain, intl }) => {

export const Domain: React.FC<Props> = ({ domain, onUnblockDomain }) => {
const intl = useIntl();

const handleDomainUnblock = useCallback(() => {
onUnblockDomain(domain);
}, [domain, onUnblockDomain]);
Expand All @@ -41,5 +42,3 @@ const _Domain: React.FC<Props> = ({ domain, onUnblockDomain, intl }) => {
</div>
);
};

export const Domain = injectIntl(_Domain);
10 changes: 4 additions & 6 deletions app/javascript/mastodon/components/load_gap.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback } from 'react';

import type { InjectedIntl } from 'react-intl';
import { injectIntl, defineMessages } from 'react-intl';
import { useIntl, defineMessages } from 'react-intl';

import { Icon } from 'mastodon/components/icon';

Expand All @@ -13,10 +12,11 @@ interface Props {
disabled: boolean;
maxId: string;
onClick: (maxId: string) => void;
intl: InjectedIntl;
}

const _LoadGap: React.FC<Props> = ({ disabled, maxId, onClick, intl }) => {
export const LoadGap: React.FC<Props> = ({ disabled, maxId, onClick }) => {
const intl = useIntl();

const handleClick = useCallback(() => {
onClick(maxId);
}, [maxId, onClick]);
Expand All @@ -32,5 +32,3 @@ const _LoadGap: React.FC<Props> = ({ disabled, maxId, onClick, intl }) => {
</button>
);
};

export const LoadGap = injectIntl(_LoadGap);
14 changes: 7 additions & 7 deletions app/javascript/mastodon/components/relative_timestamp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'react';

import type { InjectedIntl } from 'react-intl';
import type { IntlShape } from 'react-intl';
import { injectIntl, defineMessages } from 'react-intl';

const messages = defineMessages({
Expand Down Expand Up @@ -103,7 +103,7 @@ const getUnitDelay = (units: string) => {
};

export const timeAgoString = (
intl: InjectedIntl,
intl: IntlShape,
date: Date,
now: number,
year: number,
Expand Down Expand Up @@ -155,7 +155,7 @@ export const timeAgoString = (
};

const timeRemainingString = (
intl: InjectedIntl,
intl: IntlShape,
date: Date,
now: number,
timeGiven = true
Expand Down Expand Up @@ -190,7 +190,7 @@ const timeRemainingString = (
};

interface Props {
intl: InjectedIntl;
intl: IntlShape;
timestamp: string;
year: number;
futureDate?: boolean;
Expand All @@ -201,7 +201,7 @@ interface States {
}
class RelativeTimestamp extends Component<Props, States> {
state = {
now: this.props.intl.now(),
now: Date.now(),
};

static defaultProps = {
Expand All @@ -223,7 +223,7 @@ class RelativeTimestamp extends Component<Props, States> {

UNSAFE_componentWillReceiveProps(nextProps: Props) {
if (this.props.timestamp !== nextProps.timestamp) {
this.setState({ now: this.props.intl.now() });
this.setState({ now: Date.now() });
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ class RelativeTimestamp extends Component<Props, States> {
: Math.max(updateInterval, unitRemainder);

this._timer = window.setTimeout(() => {
this.setState({ now: this.props.intl.now() });
this.setState({ now: Date.now() });
}, delay);
}

Expand Down
9 changes: 4 additions & 5 deletions app/javascript/mastodon/containers/admin_component.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';

import { getLocale } from '../locales';
import { getLocale, onProviderError } from '../locales';

const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();

export default class AdminComponent extends PureComponent {

Expand All @@ -19,7 +18,7 @@ export default class AdminComponent extends PureComponent {
const { locale, children } = this.props;

return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
{children}
</IntlProvider>
);
Expand Down
9 changes: 4 additions & 5 deletions app/javascript/mastodon/containers/compose_container.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';

import { Provider } from 'react-redux';

import { fetchCustomEmojis } from '../actions/custom_emojis';
import { hydrateStore } from '../actions/store';
import Compose from '../features/standalone/compose';
import initialState from '../initial_state';
import { getLocale } from '../locales';
import { getLocale, onProviderError } from '../locales';
import { store } from '../store';

const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();

if (initialState) {
store.dispatch(hydrateStore(initialState));
Expand All @@ -31,7 +30,7 @@ export default class TimelineContainer extends PureComponent {
const { locale } = this.props;

return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
<Provider store={store}>
<Compose />
</Provider>
Expand Down
9 changes: 4 additions & 5 deletions app/javascript/mastodon/containers/mastodon.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';

import { Helmet } from 'react-helmet';
import { BrowserRouter, Route } from 'react-router-dom';
Expand All @@ -16,11 +16,10 @@ import { connectUserStream } from 'mastodon/actions/streaming';
import ErrorBoundary from 'mastodon/components/error_boundary';
import UI from 'mastodon/features/ui';
import initialState, { title as siteTitle } from 'mastodon/initial_state';
import { getLocale } from 'mastodon/locales';
import { getLocale, onProviderError } from 'mastodon/locales';
import { store } from 'mastodon/store';

const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();

const title = process.env.NODE_ENV === 'production' ? siteTitle : `${siteTitle} (Dev)`;

Expand Down Expand Up @@ -83,7 +82,7 @@ export default class Mastodon extends PureComponent {
const { locale } = this.props;

return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
<ReduxProvider store={store}>
<ErrorBoundary>
<BrowserRouter>
Expand Down
9 changes: 4 additions & 5 deletions app/javascript/mastodon/containers/media_container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { createPortal } from 'react-dom';

import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';

import { fromJS } from 'immutable';

Expand All @@ -14,11 +14,10 @@ import Audio from 'mastodon/features/audio';
import Card from 'mastodon/features/status/components/card';
import MediaModal from 'mastodon/features/ui/components/media_modal';
import Video from 'mastodon/features/video';
import { getLocale } from 'mastodon/locales';
import { getLocale, onProviderError } from 'mastodon/locales';
import { getScrollbarWidth } from 'mastodon/utils/scrollbar';

const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();

const MEDIA_COMPONENTS = { MediaGallery, Video, Card, Poll, Hashtag, Audio };

Expand Down Expand Up @@ -84,7 +83,7 @@ export default class MediaContainer extends PureComponent {
}

return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
<>
{[].map.call(components, (component, i) => {
const componentName = component.getAttribute('data-component');
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/mastodon/features/onboarding/follows.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { FormattedMessage, FormattedHTMLMessage } from 'react-intl';
import { FormattedMessage } from 'react-intl';

import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -77,7 +77,7 @@ class Follows extends PureComponent {
{loadedContent}
</div>

<p className='onboarding__lead'><FormattedHTMLMessage id='onboarding.tips.accounts_from_other_servers' defaultMessage='<strong>Did you know?</strong> Since Mastodon is decentralized, some profiles you come across will be hosted on servers other than yours. And yet you can interact with them seamlessly! Their server is in the second half of their username!' /></p>
<p className='onboarding__lead'><FormattedMessage id='onboarding.tips.accounts_from_other_servers' defaultMessage='<strong>Did you know?</strong> Since Mastodon is decentralized, some profiles you come across will be hosted on servers other than yours. And yet you can interact with them seamlessly! Their server is in the second half of their username!' values={{ strong: chunks => <strong>{chunks}</strong> }} /></p>

<div className='onboarding__footer'>
<button className='link-button' onClick={onBack}><FormattedMessage id='onboarding.actions.back' defaultMessage='Take me back' /></button>
Expand Down
8 changes: 4 additions & 4 deletions app/javascript/mastodon/features/onboarding/share.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { defineMessages, injectIntl, FormattedMessage, FormattedHTMLMessage } from 'react-intl';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';

import classNames from 'classnames';
import { Link } from 'react-router-dom';
Expand Down Expand Up @@ -168,9 +168,9 @@ class Share extends PureComponent {
<CopyPasteText value={intl.formatMessage(messages.shareableMessage, { username: `@${account.get('username')}@${domain}`, url })} />

<TipCarousel>
<div><p className='onboarding__lead'><FormattedHTMLMessage id='onboarding.tips.verification' defaultMessage='<strong>Did you know?</strong> You can verify your account by putting a link to your Mastodon profile on your own website and adding the website to your profile. No fees or documents necessary!' /></p></div>
<div><p className='onboarding__lead'><FormattedHTMLMessage id='onboarding.tips.migration' defaultMessage='<strong>Did you know?</strong> If you feel like {domain} is not a great server choice for you in the future, you can move to another Mastodon server without losing your followers. You can even host your own server!' values={{ domain }} /></p></div>
<div><p className='onboarding__lead'><FormattedHTMLMessage id='onboarding.tips.2fa' defaultMessage='<strong>Did you know?</strong> You can secure your account by setting up two-factor authentication in your account settings. It works with any TOTP app of your choice, no phone number necessary!' /></p></div>
<div><p className='onboarding__lead'><FormattedMessage id='onboarding.tips.verification' defaultMessage='<strong>Did you know?</strong> You can verify your account by putting a link to your Mastodon profile on your own website and adding the website to your profile. No fees or documents necessary!' values={{ strong: chunks => <strong>{chunks}</strong> }} /></p></div>
<div><p className='onboarding__lead'><FormattedMessage id='onboarding.tips.migration' defaultMessage='<strong>Did you know?</strong> If you feel like {domain} is not a great server choice for you in the future, you can move to another Mastodon server without losing your followers. You can even host your own server!' values={{ domain, strong: chunks => <strong>{chunks}</strong> }} /></p></div>
<div><p className='onboarding__lead'><FormattedMessage id='onboarding.tips.2fa' defaultMessage='<strong>Did you know?</strong> You can secure your account by setting up two-factor authentication in your account settings. It works with any TOTP app of your choice, no phone number necessary!' values={{ strong: chunks => <strong>{chunks}</strong> }} /></p></div>
</TipCarousel>

<p className='onboarding__lead'><FormattedMessage id='onboarding.share.next_steps' defaultMessage='Possible next steps:' /></p>
Expand Down
14 changes: 14 additions & 0 deletions app/javascript/mastodon/load_locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { setLocale } from "./locales";

export async function loadLocale() {
const locale = document.querySelector('html').lang || 'en';

const localeData = await import(
/* webpackMode: "lazy" */
/* webpackChunkName: "locale/[request]" */
/* webpackInclude: /\.json$/ */
/* webpackPreload: true */
`mastodon/locales/${locale}.json`);

setLocale({ messages: localeData });
}

0 comments on commit 44cd88a

Please sign in to comment.