mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
b0215738a2
* storybook - i18n toolbar * lint fix
58 lines
1.2 KiB
JavaScript
58 lines
1.2 KiB
JavaScript
import React, { Component, createContext, useMemo } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { getMessage } from '../ui/app/helpers/utils/i18n-helper';
|
|
import { I18nContext } from '../ui/app/contexts/i18n';
|
|
|
|
export { I18nContext }
|
|
|
|
export const I18nProvider = (props) => {
|
|
const { currentLocale, current, en } = props
|
|
|
|
const t = useMemo(() => {
|
|
return (key, ...args) =>
|
|
getMessage(currentLocale, current, key, ...args) ||
|
|
getMessage(currentLocale, en, key, ...args);
|
|
}, [currentLocale, current, en]);
|
|
|
|
return (
|
|
<I18nContext.Provider value={t}>{props.children}</I18nContext.Provider>
|
|
);
|
|
};
|
|
|
|
I18nProvider.propTypes = {
|
|
currentLocale: PropTypes.string,
|
|
current: PropTypes.object,
|
|
en: PropTypes.object,
|
|
children: PropTypes.node,
|
|
};
|
|
|
|
I18nProvider.defaultProps = {
|
|
children: undefined,
|
|
};
|
|
|
|
export class LegacyI18nProvider extends Component {
|
|
static propTypes = {
|
|
children: PropTypes.node,
|
|
};
|
|
|
|
static defaultProps = {
|
|
children: undefined,
|
|
};
|
|
|
|
static contextType = I18nContext;
|
|
|
|
static childContextTypes = {
|
|
t: PropTypes.func,
|
|
};
|
|
|
|
getChildContext() {
|
|
return {
|
|
t: this.context,
|
|
};
|
|
}
|
|
|
|
render() {
|
|
return this.props.children;
|
|
}
|
|
}
|