From f1785faa08424f56f97be8d1410fe1a521ff7a35 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 24 Sep 2016 15:05:46 +0300 Subject: [PATCH] Multilanguage BitmapText component --- src/components/text/BitmapText.jsx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/text/BitmapText.jsx b/src/components/text/BitmapText.jsx index b982e40..6fee920 100644 --- a/src/components/text/BitmapText.jsx +++ b/src/components/text/BitmapText.jsx @@ -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);