2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import * as Sentry from '@sentry/browser';
|
2023-06-20 14:44:11 +02:00
|
|
|
import {
|
|
|
|
I18NMessageDict,
|
|
|
|
I18NSubstitution,
|
|
|
|
getMessage as getMessageShared,
|
|
|
|
} from '../../../shared/modules/i18n';
|
2023-06-15 13:38:07 +02:00
|
|
|
import { NETWORK_TYPES } from '../../../shared/constants/network';
|
2021-01-19 17:41:57 +01:00
|
|
|
|
2018-07-09 22:07:06 +02:00
|
|
|
/**
|
|
|
|
* Returns a localized message for the given key
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2023-01-31 13:01:10 +01:00
|
|
|
* @param localeCode - The code for the current locale
|
|
|
|
* @param localeMessages - The map of messages for the current locale
|
|
|
|
* @param key - The message key
|
|
|
|
* @param substitutions - A list of message substitution replacements can replace $n in given message
|
|
|
|
* @returns The localized message
|
2018-07-09 22:07:06 +02:00
|
|
|
*/
|
2023-01-31 13:01:10 +01:00
|
|
|
export const getMessage = (
|
|
|
|
localeCode: string,
|
|
|
|
localeMessages: I18NMessageDict,
|
|
|
|
key: string,
|
|
|
|
substitutions?: string[],
|
|
|
|
): JSX.Element | string | null => {
|
2023-06-20 14:44:11 +02:00
|
|
|
const hasReactSubstitutions = substitutions?.some(
|
|
|
|
(element) =>
|
|
|
|
element !== null &&
|
|
|
|
(typeof element === 'function' || typeof element === 'object'),
|
|
|
|
);
|
2020-07-03 02:34:48 +02:00
|
|
|
|
2023-06-20 14:44:11 +02:00
|
|
|
const join = hasReactSubstitutions
|
|
|
|
? (parts: I18NSubstitution[]) => <span> {parts} </span>
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
const onError = (error: Error) => {
|
|
|
|
Sentry.captureException(error);
|
|
|
|
};
|
|
|
|
|
|
|
|
return getMessageShared(
|
|
|
|
localeCode,
|
|
|
|
localeMessages,
|
|
|
|
key,
|
|
|
|
substitutions,
|
|
|
|
onError,
|
|
|
|
join,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2023-06-20 14:44:11 +02:00
|
|
|
};
|
2023-06-15 13:38:07 +02:00
|
|
|
|
|
|
|
export function getNetworkLabelKey(network: string): string {
|
|
|
|
if (network === NETWORK_TYPES.LINEA_GOERLI) {
|
|
|
|
return 'lineaGoerli';
|
|
|
|
}
|
2023-06-16 18:35:33 +02:00
|
|
|
if (network === NETWORK_TYPES.LINEA_MAINNET) {
|
|
|
|
return 'lineaMainnet';
|
|
|
|
}
|
2023-06-15 13:38:07 +02:00
|
|
|
return network;
|
|
|
|
}
|