mirror of
https://github.com/elyby/emails-renderer.git
synced 2024-12-23 21:59:48 +05:30
Multilanguage BitmapText component
This commit is contained in:
parent
a6b6055fe8
commit
f1785faa08
@ -2,11 +2,21 @@ import { PropTypes } from 'react';
|
||||
|
||||
import { FormattedMessage as Message } from 'react-intl';
|
||||
|
||||
export default function BitmapText(props) {
|
||||
const src = require(`emails/register/images/ru/welcome.png`);
|
||||
export function BitmapText(props) {
|
||||
const parts = props.message.id.split('.');
|
||||
|
||||
if (parts[0] !== 'emails') {
|
||||
throw new Error('Only src/emails subdirectories supported for now');
|
||||
}
|
||||
|
||||
if (parts.length !== 3) {
|
||||
throw new Error('The message.id must be contain 3 parts separated by dots');
|
||||
}
|
||||
|
||||
const src = require(`emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`);
|
||||
// TODO: we can improve this loader in future by adding an option to disable file emitting
|
||||
// because this thing is handled by url-loader
|
||||
const size = require(`image-size!emails/register/images/ru/welcome.png`);
|
||||
const size = require(`image-size!emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`);
|
||||
|
||||
const width = props.retina ? size.width / 2 : size.width;
|
||||
const height = props.retina ? size.height / 2 : size.height;
|
||||
@ -35,3 +45,9 @@ BitmapText.propTypes = {
|
||||
BitmapText.defaultProps = {
|
||||
retina: true
|
||||
};
|
||||
|
||||
import { injectIntl, intlShape } from 'react-intl';
|
||||
|
||||
BitmapText.propTypes.intl = intlShape;
|
||||
|
||||
export default injectIntl(BitmapText);
|
||||
|
Loading…
Reference in New Issue
Block a user