Skip to content

Commit

Permalink
feat - updated script to generateLocales to notify usage of Formatted…
Browse files Browse the repository at this point in the history
…HTMLMessage, dynamic FormattedMessage, invalid defaultMessage
  • Loading branch information
Lyncee59 committed May 23, 2018
1 parent f0f11e9 commit 1b69629
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ const selectStyle = status => {
const renderStatus = (status, isBuy) => {
switch (status) {
case 'awaiting_transfer_in':
case 'processing': return isBuy ? <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.processingbuy' defaultMessage='Pending Buy' /> : <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.processingsell' defaultMessage='Pending Sell' />

case 'completed': return isBuy ? <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.completedbuy' defaultMessage='Completed Buy' /> : <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.completedsell' defaultMessage='Completed Sell' />
case 'processing': return isBuy
? <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.processingbuy' defaultMessage='Pending Buy' />
: <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.processingsell' defaultMessage='Pending Sell' />
case 'completed': return isBuy
? <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.completedbuy' defaultMessage='Completed Buy' />
: <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.completedsell' defaultMessage='Completed Sell' />
case 'rejected': return <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.rejected' defaultMessage='Rejected' />
case 'failed': return <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.failed' defaultMessage='Failed' />
case 'cancelled': return <FormattedMessage id='scenes.buysellorderhistory.list.orderstatus.cancelled' defaultMessage='Cancelled' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class SfoxTradeDetails extends React.PureComponent {
<FormattedMessage id='order_details.trade_id' defaultMessage='Your order ID is: SFX-{id}' values={{ id: trade.id }} />
</Text>
<Text style={spacing('mt-20')} size='14px' weight={400}>
{ trade.isBuy ? <FormattedMessage id='order_details.method' defaultMessage='Payment Method' /> : <FormattedMessage id='order_details.receiving_funds_into' defaultMessage='Receiving Funds Into' /> }
{ trade.isBuy
? <FormattedMessage id='order_details.method' defaultMessage='Payment Method' />
: <FormattedMessage id='order_details.receiving_funds_into' defaultMessage='Receiving Funds Into' /> }
</Text>
<MethodContainer borderDark style={spacing('mt-5')}>
<Icon name='bank-filled' size='30px' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const OrderCheckout = ({ quoteR, rateQuoteR, account, onFetchQuote, reason, limi
output: 'btc'
}
const disableInputs = limits.max < limits.min || (reason.indexOf('has_remaining') < 0 && reason) || limits.effectiveMax < limits.min
const wantToHelper = () => type === 'buy' ? <FormattedMessage id='buy.output_method.title.buy' defaultMessage='I want to buy' /> : <FormattedMessage id='buy.output_method.title.sell' defaultMessage='I want to sell' />
const wantToHelper = () => type === 'buy'
? <FormattedMessage id='buy.output_method.title.buy' defaultMessage='I want to buy' />
: <FormattedMessage id='buy.output_method.title.sell' defaultMessage='I want to sell' />

const limitsHelper = (quoteR, limits) => {
if (quoteR.error) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ const quoteInputSpec = {
const OrderCheckout = ({ quoteR, account, onFetchQuote, reason, finishAccountSetup, limits, type }) => {
const disableInputs = limits.max < limits.min || (reason.indexOf('has_remaining') < 0 && reason) || limits.effectiveMax < limits.min

const wantToHelper = () => type === 'buy' ? <FormattedMessage id='buy.output_method.title.buy' defaultMessage='I want to buy' /> : <FormattedMessage id='buy.output_method.title.sell' defaultMessage='I want to sell' />
const payWithHelper = () => type === 'buy' ? <FormattedMessage id='buy.input_method.title.buy_with' defaultMessage='I will pay with' /> : <FormattedMessage id='buy.output_method.title.sell_with' defaultMessage='I will receive funds into' />
const wantToHelper = () => type === 'buy'
? <FormattedMessage id='buy.output_method.title.buy' defaultMessage='I want to buy' />
: <FormattedMessage id='buy.output_method.title.sell' defaultMessage='I want to sell' />
const payWithHelper = () => type === 'buy'
? <FormattedMessage id='buy.input_method.title.buy_with' defaultMessage='I will pay with' />
: <FormattedMessage id='buy.output_method.title.sell_with' defaultMessage='I will receive funds into' />

const limitsHelper = (quoteR, limits) => {
if (quoteR.error) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const rootPath = path.resolve(`${__dirname}/../src`)
const outputPath = rootPath + '/assets/locales'
const outputFilename = 'en.json'
// const regexIntlImport = new RegExp(/.+from['" ]+react-intl['" ]+/)
const regexIntlComponent = new RegExp(/(<FormattedMessage[^>]+\/>)/, 'gm')
const regexIntlComponent = new RegExp(/(<FormattedMessage([^>])+\/>|<FormattedHTMLMessage(.+)+\/>)/, 'gm')
const regexIntlId = new RegExp(/id='([^']+)'/)
const regexIntlMessage = new RegExp(/defaultMessage='([^']+)'|defaultMessage="(.+)"/)

Expand Down Expand Up @@ -49,11 +49,16 @@ export const elements = data => data.match(regexIntlComponent)
export const toKeyValue = element => {
const id = element.match(regexIntlId)
const message = element.match(regexIntlMessage)
if (isNotNil(id) && isNotNil(message)) {
return {[id[1]]: message[1]}
if (isNil(id) && isNil(message)) {
console.warn('Invalid FormattedMessage (Dynamic): ' + element)
} else if (element.includes('FormattedHTMLMessage')) {
console.log('Invalid FormattedMessage (HTML Injection): ' + element)
} else if (isNil(id)) {
console.log('Invalid ID: ' + element)
} else if (isNil(message)) {
console.log('Invalid Message: ' + element)
} else {
console.warn('FAILED TO ADD KEY : ', (id || [])[1], (message || [])[1])
return {}
return { [id[1]]: message[1] }
}
}

Expand Down

0 comments on commit 1b69629

Please sign in to comment.