Skip to content

Instantly share code, notes, and snippets.

@coryf
Created May 21, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryf/41f964fc815107276cfd0f2343774685 to your computer and use it in GitHub Desktop.
Save coryf/41f964fc815107276cfd0f2343774685 to your computer and use it in GitHub Desktop.
import React from 'react'
import i18n from 'i18n-js'
import { sanitize } from 'dompurify'
import _ from 'lodash'
export const htmlTranslate = (scope, options) => {
if (!scope.endsWith('_html')) {
return i18n.t(scope, options)
}
const tag = options['tag'] || 'span'
const escapedInterpolations = _.mapValues(options, dompurify)
const html = i18n.t(scope, escapedInterpolations)
return React.createElement(tag, { dangerouslySetInnerHTML: { __html: html } })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment