Skip to content

Commit

Permalink
fix: Only showing some warning messages in development, instead of de…
Browse files Browse the repository at this point in the history
…v and tests.
  • Loading branch information
davidjoy committed Sep 26, 2024
1 parent e793472 commit 81acba9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions runtime/i18n/injectIntlWithShim.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { injectIntl } from 'react-intl';
import { getLoggingService, intlShape } from './lib';
import { EnvironmentTypes } from '../../types';
import { getConfig } from '../config';
import { getLoggingService, intlShape } from './lib';

/**
* This function wraps react-intl's injectIntl function in order to add error logging to the intl
Expand All @@ -18,7 +19,7 @@ const injectIntlWithShim = (WrappedComponent) => {
value: (definition, ...args) => {
if (definition === undefined || definition.id === undefined) {
const error = new Error('i18n error: An undefined message was supplied to intl.formatMessage.');
if (getConfig().ENVIRONMENT !== 'production') {
if (getConfig().ENVIRONMENT === EnvironmentTypes.DEVELOPMENT) {
console.error(error); // eslint-disable-line no-console
return '!!! Missing message supplied to intl.formatMessage !!!';
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/i18n/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import '@formatjs/intl-relativetimeformat/locale-data/th';
import '@formatjs/intl-relativetimeformat/locale-data/uk';
import '@formatjs/intl-relativetimeformat/locale-data/zh';

import { SiteConfig } from '../../types';
import { EnvironmentTypes, SiteConfig } from '../../types';
import { LoggingService } from '../logging/types';

const cookies = new Cookies();
Expand Down Expand Up @@ -287,7 +287,7 @@ export function configure(options: ConfigureI18nOptions) {
config = options.config;
messages = Array.isArray(options.messages) ? merge({}, ...options.messages) : options.messages;

if (config.ENVIRONMENT !== 'production' && messages !== undefined) {
if (config.ENVIRONMENT === EnvironmentTypes.DEVELOPMENT && messages !== undefined) {
Object.keys(messages).forEach((key) => {
if (supportedLocales.indexOf(key) < 0) {
console.warn(`Unexpected locale: ${key}`); // eslint-disable-line no-console
Expand Down

0 comments on commit 81acba9

Please sign in to comment.