Use helpers to check environment in frontend (#27633)

This commit is contained in:
Renaud Chaput 2023-10-31 17:05:44 +01:00 committed by GitHub
parent 7ef56d6e50
commit 277e6968f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 9 deletions

View file

@ -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: {} };

View file

@ -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