2019-04-24 06:23:46 +08:00
|
|
|
import React, { Component } from 'react';
|
2021-04-01 19:14:24 +08:00
|
|
|
import { IntlProvider, FormattedMessage } from 'react-intl';
|
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2019-04-24 06:23:46 +08:00
|
|
|
import './styles.css';
|
|
|
|
|
2019-07-24 21:38:38 +08:00
|
|
|
|
|
|
|
// currently supported locales.
|
2020-05-26 04:00:13 +08:00
|
|
|
// import ar from 'react-intl/locale-data/ar';
|
|
|
|
// import bg from 'react-intl/locale-data/bg';
|
|
|
|
// import cs from 'react-intl/locale-data/cs';
|
|
|
|
// import de from 'react-intl/locale-data/de';
|
|
|
|
// import el from 'react-intl/locale-data/el';
|
|
|
|
// import en from 'react-intl/locale-data/en';
|
|
|
|
// import es from 'react-intl/locale-data/es';
|
|
|
|
// import eu from 'react-intl/locale-data/eu';
|
|
|
|
// import fa from 'react-intl/locale-data/fa';
|
|
|
|
// import fi from 'react-intl/locale-data/fi';
|
|
|
|
// import fr from 'react-intl/locale-data/fr';
|
|
|
|
// import he from 'react-intl/locale-data/he';
|
|
|
|
// import hi from 'react-intl/locale-data/hi';
|
|
|
|
// import hu from 'react-intl/locale-data/hu';
|
|
|
|
// import id from 'react-intl/locale-data/id';
|
|
|
|
// import it from 'react-intl/locale-data/it';
|
|
|
|
// import ja from 'react-intl/locale-data/ja';
|
|
|
|
// import km from 'react-intl/locale-data/km';
|
|
|
|
// import pl from 'react-intl/locale-data/pl';
|
|
|
|
// import pt from 'react-intl/locale-data/pt';
|
|
|
|
// import ru from 'react-intl/locale-data/ru';
|
|
|
|
// import sv from 'react-intl/locale-data/sv';
|
|
|
|
// import tr from 'react-intl/locale-data/tr';
|
|
|
|
// import uk from 'react-intl/locale-data/uk';
|
|
|
|
// import vi from 'react-intl/locale-data/vi';
|
|
|
|
// import zh from 'react-intl/locale-data/zh';
|
2019-07-24 21:38:38 +08:00
|
|
|
|
2020-05-26 04:00:13 +08:00
|
|
|
// // This class is the only component loaded on legacy (unsupported) browsers.
|
|
|
|
// // What is included here needs to be minimal and carefully considered because some
|
|
|
|
// // things can't be polyfilled.
|
2019-04-24 06:23:46 +08:00
|
|
|
|
2020-05-26 04:00:13 +08:00
|
|
|
// addLocaleData([
|
|
|
|
// ...ar,
|
|
|
|
// ...bg,
|
|
|
|
// ...cs,
|
|
|
|
// ...de,
|
|
|
|
// ...el,
|
|
|
|
// ...en,
|
|
|
|
// ...es,
|
|
|
|
// ...eu,
|
|
|
|
// ...fa,
|
|
|
|
// ...fi,
|
|
|
|
// ...fr,
|
|
|
|
// ...he,
|
|
|
|
// ...hi,
|
|
|
|
// ...hu,
|
|
|
|
// ...id,
|
|
|
|
// ...it,
|
|
|
|
// ...ja,
|
|
|
|
// ...km,
|
|
|
|
// ...pl,
|
|
|
|
// ...pt,
|
|
|
|
// ...ru,
|
|
|
|
// ...sv,
|
|
|
|
// ...tr,
|
|
|
|
// ...uk,
|
|
|
|
// ...vi,
|
|
|
|
// ...zh,
|
|
|
|
// ]);
|
2019-07-24 21:38:38 +08:00
|
|
|
|
2019-04-24 06:23:46 +08:00
|
|
|
const FETCHING = 'fetching';
|
|
|
|
const FALLBACK = 'fallback';
|
|
|
|
const READY = 'ready';
|
2021-04-01 19:14:24 +08:00
|
|
|
const supportedBrowsers = ['Chrome', 'Firefox', 'Safari', 'Opera', 'Microsoft Edge', 'Yandex Browser'];
|
2021-03-11 19:42:41 +08:00
|
|
|
const DEFAULT_LANGUAGE = Meteor.settings.public.app.defaultSettings.application.fallbackLocale;
|
2019-04-24 06:23:46 +08:00
|
|
|
|
|
|
|
export default class Legacy extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
const locale = navigator.languages ? navigator.languages[0] : false
|
2021-03-11 19:42:41 +08:00
|
|
|
|| navigator.language;
|
2019-04-24 06:23:46 +08:00
|
|
|
|
2020-11-19 04:31:36 +08:00
|
|
|
const url = `./locale?locale=${locale}`;
|
2021-03-11 19:42:41 +08:00
|
|
|
const localesPath = 'locales';
|
2019-04-24 06:23:46 +08:00
|
|
|
|
|
|
|
const that = this;
|
|
|
|
this.state = { viewState: FETCHING };
|
|
|
|
fetch(url)
|
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.json();
|
|
|
|
})
|
2021-03-11 19:42:41 +08:00
|
|
|
.then(({ normalizedLocale, regionDefaultLocale }) => {
|
|
|
|
fetch(`${localesPath}/${DEFAULT_LANGUAGE}.json`)
|
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then((messages) => {
|
|
|
|
if (regionDefaultLocale !== '') {
|
|
|
|
fetch(`${localesPath}/${regionDefaultLocale}.json`)
|
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then((regionDefaultMessages) => {
|
|
|
|
messages = Object.assign(messages, regionDefaultMessages);
|
|
|
|
this.setState({ messages});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (normalizedLocale && normalizedLocale !== DEFAULT_LANGUAGE && normalizedLocale !== regionDefaultLocale) {
|
|
|
|
fetch(`${localesPath}/${normalizedLocale}.json`)
|
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then((localeMessages) => {
|
|
|
|
messages = Object.assign(messages, localeMessages);
|
|
|
|
this.setState({ messages});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
normalizedLocale = (regionDefaultLocale) || DEFAULT_LANGUAGE;
|
|
|
|
const dasherizedLocale = normalizedLocale.replace('_', '-');
|
|
|
|
this.setState({ messages, normalizedLocale: dasherizedLocale, viewState: READY });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return messages;
|
|
|
|
})
|
|
|
|
.then((messages) => {
|
|
|
|
const dasherizedLocale = normalizedLocale.replace('_', '-');
|
|
|
|
this.setState({ messages, normalizedLocale: dasherizedLocale, viewState: READY });
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
that.setState({ viewState: FALLBACK });
|
|
|
|
});
|
2019-04-24 06:23:46 +08:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
that.setState({ viewState: FALLBACK });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-04-01 19:14:24 +08:00
|
|
|
const { browserName, isChrome } = browserInfo;
|
|
|
|
const { isIos } = deviceInfo;
|
|
|
|
|
2019-04-24 06:23:46 +08:00
|
|
|
const { messages, normalizedLocale, viewState } = this.state;
|
2020-01-25 01:22:45 +08:00
|
|
|
const isSupportedBrowser = supportedBrowsers.includes(browserName);
|
2021-04-01 19:14:24 +08:00
|
|
|
const isChromeIos = isIos && isChrome;
|
2019-06-22 01:45:34 +08:00
|
|
|
|
|
|
|
let messageId = isSupportedBrowser ? 'app.legacy.upgradeBrowser' : 'app.legacy.unsupportedBrowser';
|
|
|
|
if (isChromeIos) messageId = 'app.legacy.criosBrowser';
|
2019-04-24 06:23:46 +08:00
|
|
|
|
|
|
|
switch (viewState) {
|
|
|
|
case READY:
|
|
|
|
return (
|
|
|
|
<IntlProvider locale={normalizedLocale} messages={messages}>
|
|
|
|
<p className="browserWarning">
|
|
|
|
<FormattedMessage
|
2019-06-22 01:45:34 +08:00
|
|
|
id={messageId}
|
2019-04-24 06:23:46 +08:00
|
|
|
description="Warning when someone joins with a browser that isnt supported"
|
|
|
|
values={{
|
|
|
|
0: <a href="https://www.google.com/chrome/">Chrome</a>,
|
|
|
|
1: <a href="https://getfirefox.com">Firefox</a>,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</IntlProvider>
|
|
|
|
);
|
|
|
|
case FALLBACK:
|
|
|
|
return (
|
|
|
|
<p className="browserWarning">
|
2019-06-22 01:45:34 +08:00
|
|
|
{isChromeIos ? (
|
|
|
|
<span>Please use Safari on iOS for full support.</span>
|
|
|
|
) : (
|
|
|
|
<span>
|
|
|
|
<span>
|
|
|
|
It looks like you're using a browser that
|
|
|
|
is not fully supported. Please use either
|
|
|
|
{' '}
|
|
|
|
</span>
|
|
|
|
<a href="https://www.google.com/chrome/">Chrome</a>
|
|
|
|
<span> or </span>
|
|
|
|
<a href="https://getfirefox.com">Firefox</a>
|
|
|
|
<span> for full support.</span>
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|
2019-04-24 06:23:46 +08:00
|
|
|
</p>
|
|
|
|
);
|
|
|
|
case FETCHING:
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|