Use helpers to check environment in frontend (#27633)
This commit is contained in:
parent
7ef56d6e50
commit
277e6968f5
8 changed files with 28 additions and 9 deletions
|
@ -1,3 +1,5 @@
|
|||
import { isDevelopment } from 'mastodon/utils/environment';
|
||||
|
||||
export interface LocaleData {
|
||||
locale: string;
|
||||
messages: Record<string, string>;
|
||||
|
@ -11,7 +13,7 @@ export function setLocale(locale: LocaleData) {
|
|||
|
||||
export function getLocale(): LocaleData {
|
||||
if (!loadedLocale) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (isDevelopment()) {
|
||||
throw new Error('getLocale() called before any locale has been set');
|
||||
} else {
|
||||
return { locale: 'unknown', messages: {} };
|
||||
|
|
|
@ -2,12 +2,14 @@ import { useEffect, useState } from 'react';
|
|||
|
||||
import { IntlProvider as BaseIntlProvider } from 'react-intl';
|
||||
|
||||
import { isProduction } from 'mastodon/utils/environment';
|
||||
|
||||
import { getLocale, isLocaleLoaded } from './global_locale';
|
||||
import { loadLocale } from './load_locale';
|
||||
|
||||
function onProviderError(error: unknown) {
|
||||
// Silent the error, like upstream does
|
||||
if (process.env.NODE_ENV === 'production') return;
|
||||
if (isProduction()) return;
|
||||
|
||||
// This browser does not advertise Intl support for this locale, we only print a warning
|
||||
// As-per the spec, the browser should select the best matching locale
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue